?
Solved

How to get the clientid a treenode object in a treeview

Posted on 2007-10-04
9
Medium Priority
?
2,301 Views
Last Modified: 2008-03-01
Hello,

I am using an asp.net treeview control. I need to find out what the clientid of a given TreeNode object is. To get the clientid of the treeview itself is as simple as calling treeview.clientid, however, there doesn't seem to be such a property propery for a  treenode object. I have been searching everywhere to no avai.l. Any help on this is greatly appreciated.

This is how I am adding the nodes to the tree:

 Dim Rootnode As New TreeNode("TheRoot", "TheRoot")
 TreeView1.Nodes.Add(Rootnode)

Dim childNode As New TreeNode("cars", "1")  
Rootnode .ChildNodes.Add(childNode)
'Trying to get the clientid of this node

childNode As New TreeNode("boats", "2")
Rootnode .ChildNodes.Add(childNode)

0
Comment
Question by:MAIGUI
  • 4
  • 3
8 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20018588
When you add a new node try setting the Tag property or the name property of the node to that of a primary key of the node
0
 

Author Comment

by:MAIGUI
ID: 20018950
Thank you for your reply, I was not able to find a tag or name property for this class, however, there is a text and a value property. I tried setting the value property to the PK (100794 in this case) and the code is rendered to the client as the following:

<td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','sTheRoot\\100794')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t2');" id="TreeView1t2">boats</a></td>

The thing is, with the way that the treeview renders this. It appears that I would not be able to access this node from javascript by name or id. The tree is rather large and I would prefer not to resort to iterating through all hrefs on the page and checking the innerHTML of each link to match, however, I may have to end up doing that if there is not a better way.

Thanks
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20019078
If you dont mind doing a round trip to the server, you could implenent the same without javascript.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:MAIGUI
ID: 20019270
Actually getting the clientid of the node is a means to an end. The reason I was thinking to get the clientid is because I am programatically expanding a particualr node on the server side, however, when the page renders the user has to scroll to the middle of the page to see the expanded node. I thought if I could get the clientid I could use Javascript to set the scrollbar position.  If there is a way to set the scrollbar via server side code, that would be be great too.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20019523
>>On Submit of the form you can store the current position of the tree control to a hidden variable and on load you can read the hidden variable and set the position back

>> You can also try switching "on" smart navigation. It kind of attempts to set the screen the way it was before the submit.

0
 

Author Comment

by:MAIGUI
ID: 20020460
Thank you surajguptha, I know we're gonna get this thing tackled, I can feel it. Let me just clarify the problem a little. This all happens on an initial load, no submit occuring at this point. I can post the actual code tomorrow when I get to work.
0
 

Author Comment

by:MAIGUI
ID: 20024987
Never mind, I figured this out. If you turn on EnableClientScript on the treeview, the treeview will render to the browser as treeviewName_Data. Then you can call treeviewName_Data.selectedNodeID.value to the the selected node. Thank you for your help.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21022586
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question