Geeks With Blogs
Stuff I do my notepad
Technorati Tags: ,,
TreeViewClientID_Data.selectedNodeID.value 

where TreeViewClientID_Data  is the name of the TreeView javascript object that has “selectedNodeID” property.

We can easily load this object and get selected node id like this:

   1:          Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(EndLoadedHandler);
   2:   
   3:          function EndLoadedHandler(sender, args)
   4:          {
   5:                   //* make sure that object is fully loaded
   6:                    var data = eval('<%=tvwScrollTo.ClientID %>_Data');
   7:                    if(!data)
   8:                         var selectedNodeID = data.selectedNodeID.value;
   9:           }

we have to make sure that TreeViewClientID_Data  is loaded.

or

document.getElementById('TreeViewClientID_SelectedNode').value 

where TreeViewClientID_SelectedNode is the id of the hidden field where selected node id is stored

 

Explained:

TreeViewClientID_Data has a lot of useful information. You can find this object in the source of the page:

TreeView_Data

We can clearly see that selected node id is stored in the hidden field with the name 'TreeViewClientID_SelectedNode'

So, lets grab it:

document.getElementById('TreeViewClientID_SelectedNode').value 

or dynamically

document.getElementById('<%=tvwScrollTo.ClientID %>_SelectedNode').value

 

Happy programming!

Posted on Monday, January 25, 2010 11:04 PM | Back to top


Comments on this post: Get ASP.NET TreeView – get selected node id on the client side

# re: Get ASP.NET TreeView – get selected node id on the client side
Requesting Gravatar...
Where put this code:
"Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(EndLoadedHandler);"
and how to call this function?
Left by mahdi on Jun 14, 2010 5:12 AM

# re: Get ASP.NET TreeView – get selected node id on the client side
Requesting Gravatar...
Any way to do the same but with checked nodes?

Thank u in advanced!
Left by Almudena on Aug 31, 2012 3:34 PM

Your comment:
 (will show your gravatar)


Copyright © vladimirl | Powered by: GeeksWithBlogs.net