TreeView: How to call client script on node selected?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antonio

    TreeView: How to call client script on node selected?

    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_Selecte dNodeChanged(By Val sender As Object, _
    ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged

    If tvwMain.Selecte dValue.ToUpper = "EXIT" Then

    Response.Write( "<script language='javas cript'
    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

  • pushpi

    #2
    Re: TreeView: How to call client script on node selected?

    On Jan 25, 1:06 am, "Antonio" <antoni...@hotm ail.comwrote:
    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, myTreeViewcontr ol 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_Selecte dNodeChanged(By Val sender As Object, _
    ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged
    >
    If tvwMain.Selecte dValue.ToUpper = "EXIT" Then
    >
    Response.Write( "<script language='javas cript'
    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.getEle mentById("<%=Tr ee1.ClientID %>"); //
    use your treeview id instead of Tree1
    var treeLinks = treeview.getEle mentsByTagName( "a");
    for(i=0;i<treeL inks.length;i++ )
    {
    if(treeLinks[i].firstChild.tag Name != "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.select action to selectaction.se lect
    to show hand on the treenode hover.

    Hope this helps.

    Comment

    • pushpi

      #3
      Re: TreeView: How to call client script on node selected?

      On Jan 25, 1:06 am, "Antonio" <antoni...@hotm ail.comwrote:
      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, myTreeViewcontr ol 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_Selecte dNodeChanged(By Val sender As Object, _
      ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged
      >
      If tvwMain.Selecte dValue.ToUpper = "EXIT" Then
      >
      Response.Write( "<script language='javas cript'
      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" <antoni...@hotm ail.comwrote:
      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, myTreeViewcontr ol 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_Selecte dNodeChanged(By Val sender As Object, _
      ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged
      >
      If tvwMain.Selecte dValue.ToUpper = "EXIT" Then
      >
      Response.Write( "<script language='javas cript'
      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.getEle mentById("<%=Tr ee1.ClientID %>"); //
      use your treeview id instead of Tree1
      var treeLinks = treeview.getEle mentsByTagName( "a");
      for(i=0;i<treeL inks.length;i++ )
      {
      if(treeLinks[i].firstChild.tag Name != "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.select action to selectaction.se lect
      to show hand on the treenode hover.

      Hope this helps.

      Comment

      Working...