Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > TreeView: How to call client script on node selected?

Reply
Thread Tools

TreeView: How to call client script on node selected?

 
 
Antonio
Guest
Posts: n/a
 
      01-24-2007
Hi,

I would like to have my TreeNode to call window.close(); without posting
back, how can I do that? At the same time, I prefer to have a SelectAction
property that allows my TreeNode to appear as hyperlink with hand-cursor
when hover.

For your information, my TreeView control is on a master page. I have done
some tricks but when clicking the node, it does the post-back and my page
appears empty with nothing on it except the popup message box confirming to
close the browser. Below is the code:

Protected Sub tvwMain_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged

If tvwMain.SelectedValue.ToUpper = "EXIT" Then

Response.Write("<script language='javascript'
type='text/javascript'>")
Response.Write("window.close();")
Response.Write("</script>")
End If
End Sub

This is not a good solution. Anybody have better solution? Thanks in
advance.

Regards,
Antonio

 
Reply With Quote
 
 
 
 
pushpi
Guest
Posts: n/a
 
      01-30-2007
On Jan 25, 1:06 am, "Antonio" <(E-Mail Removed)> wrote:
> Hi,
>
> I would like to have my TreeNode to call window.close(); without posting
> back, how can I do that? At the same time, I prefer to have a SelectAction
> property that allows my TreeNode to appear as hyperlink with hand-cursor
> when hover.
>
> For your information, myTreeViewcontrol is on a master page. I have done
> some tricks but when clicking the node, it does the post-back and my page
> appears empty with nothing on it except the popup message box confirming to
> close the browser. Below is the code:
>
> Protected Sub tvwMain_SelectedNodeChanged(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged
>
> If tvwMain.SelectedValue.ToUpper = "EXIT" Then
>
> Response.Write("<script language='javascript'
> type='text/javascript'>")
> Response.Write("window.close();")
> Response.Write("</script>")
> End If
> End Sub
>
> This is not a good solution. Anybody have better solution? Thanks in
> advance.
>
> Regards,
> Antonio


Hi antonio,

Try putting the below script in the head of your master page:
----------------------------------------------
<script type="text/javascript">
window.onload = function(){

var treeview = document.getElementById("<%=Tree1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getElementsByTagName("a");
for(i=0;i<treeLinks.length;i++)
{
if(treeLinks[i].firstChild.tagName != "IMG")
{

treeLinks[i].onclick = function(){

//do whatever you need to do
on the click of your node
window.close();
return false; //prevents
postback
}
}
}
}</script>
--------------------------------------------------------
Additionally, set the Treeview.selectaction to selectaction.select
to show hand on the treenode hover.

Hope this helps.

 
Reply With Quote
 
 
 
 
pushpi
Guest
Posts: n/a
 
      01-30-2007
On Jan 25, 1:06 am, "Antonio" <(E-Mail Removed)> wrote:
> Hi,
>
> I would like to have my TreeNode to call window.close(); without posting
> back, how can I do that? At the same time, I prefer to have a SelectAction
> property that allows my TreeNode to appear as hyperlink with hand-cursor
> when hover.
>
> For your information, myTreeViewcontrol is on a master page. I have done
> some tricks but when clicking the node, it does the post-back and my page
> appears empty with nothing on it except the popup message box confirming to
> close the browser. Below is the code:
>
> Protected Sub tvwMain_SelectedNodeChanged(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged
>
> If tvwMain.SelectedValue.ToUpper = "EXIT" Then
>
> Response.Write("<script language='javascript'
> type='text/javascript'>")
> Response.Write("window.close();")
> Response.Write("</script>")
> End If
> End Sub
>
> This is not a good solution. Anybody have better solution? Thanks in
> advance.
>
> Regards,
> Antonio


On Jan 25, 1:06 am, "Antonio" <(E-Mail Removed)> wrote:
> Hi,
>
> I would like to have my TreeNode to call window.close(); without posting
> back, how can I do that? At the same time, I prefer to have a SelectAction
> property that allows my TreeNode to appear as hyperlink with hand-cursor
> when hover.
>
> For your information, myTreeViewcontrol is on a master page. I have done
> some tricks but when clicking the node, it does the post-back and my page
> appears empty with nothing on it except the popup message box confirming to
> close the browser. Below is the code:
>
> Protected Sub tvwMain_SelectedNodeChanged(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged
>
> If tvwMain.SelectedValue.ToUpper = "EXIT" Then
>
> Response.Write("<script language='javascript'
> type='text/javascript'>")
> Response.Write("window.close();")
> Response.Write("</script>")
> End If
> End Sub
>
> This is not a good solution. Anybody have better solution? Thanks in
> advance.
>
> Regards,
> Antonio


Hi antonio,

Try putting the below script in the head of your master page:
----------------------------------------------
<script type="text/javascript">
window.onload = function(){

var treeview = document.getElementById("<%=Tree1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getElementsByTagName("a");
for(i=0;i<treeLinks.length;i++)
{
if(treeLinks[i].firstChild.tagName != "IMG")
{

treeLinks[i].onclick = function(){

//do whatever you need to do
on the click of your node
window.close();
return false; //prevents
postback
}
}
}
}</script>
--------------------------------------------------------
Additionally, set the Treeview.selectaction to selectaction.select
to show hand on the treenode hover.

Hope this helps.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
TreeView: How to call client script on node selected? Antonio ASP .Net Web Controls 0 01-24-2007 08:06 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
"node.InsertAfter" method only inserts node on final call chris yoker XML 1 01-29-2005 09:01 PM



Advertisments