TreeView: How to call client script on node selected?

Discussion in 'ASP .Net' started by Antonio, Jan 24, 2007.

  1. Antonio

    Antonio Guest

    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
     
    Antonio, Jan 24, 2007
    #1
    1. Advertisements

  2. Antonio

    pushpi Guest

    On Jan 25, 1:06 am, "Antonio" <> 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.firstChild.tagName != "IMG")
    {

    treeLinks.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.
     
    pushpi, Jan 30, 2007
    #2
    1. Advertisements

  3. Antonio

    pushpi Guest

    On Jan 25, 1:06 am, "Antonio" <> 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" <> 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.firstChild.tagName != "IMG")
    {

    treeLinks.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.
     
    pushpi, Jan 30, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wolf
    Replies:
    0
    Views:
    624
  2. Replies:
    0
    Views:
    1,814
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,634
    Dimitre Novatchev
    Aug 24, 2006
  4. Jake

    Setting the selected node of a treeview client side

    Jake, Jul 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    284
  5. Antonio

    TreeView: How to call client script on node selected?

    Antonio, Jan 24, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    166
    Antonio
    Jan 24, 2007
Loading...

Share This Page