working with TreeView, jscript/client side

D

Daves

Sorry folks but I will be reposting this question from 6/5 until someone
gives me an answer - the question is very easy and so ought the answer to
be. I really need the answer!

-------
I'm sorry for reposting but I've already googled for hours and I see others
have asked about this here without getting replies, this is starting to look
like some Bermuda phenomenon nobody wants to answer to! I really need to
accomplish the task below...

---
Is there any documentation out there to find out if and then how I can work
with TreeView on client side through jscript? For example I want to change
title of nodes and remove without doing postback. MS doesn't seem to have
any official documentation on this.

And please notice I'm not refering to IE TreeView control but asp.net 2.0's
TreeView!
 
G

Guest

I may be able to help you out with this.

The biggest problem with the TreeNode is that you cannot retrieve the ID for
the node on the client side. The ID for the anchor tag that represents the
node is made up from the name of the containing control (sometimes prefixed
by the master page container control name), a "t", and a private index number
of the TreeNode.

You can get around this, but you end up limiting the current functionality
of the tree node.

To enable changing of the node text on the client side, create a new class
that inherits from the TreeNode. Override the RenderPreText method and add
the following code:

protected override void RenderPreText(HtmlTextWriter writer)
{
writer.WriteBeginTag("a");
writer.WriteAttribute("id", "a" + this.ValuePath);
writer.Write("This is the node text! Awesome!");
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
base.RenderPreText(writer);
}
If you don't set the TreeNode.Text value, then this tag will be all the user
sees.
This puts an additional anchor tag in the treenode with an id (a +
node.ValuePath) that you can determine programatically at run time. In order
for the TreeView to use this (let's call it) AdvancedTreeNode, you also have
to create a new AdvancedTreeView that extends the TreeView. Override the
CreateNode method that creates a new AdvancedTreeNode and returns it
(implicitly cast to a TreeNode) thusly:

protected override TreeNode CreateNode()
{
return new AdvancedTreeNode(this, false);
}

You can alter the AdvancedTreeNode's new anchor tag so that it performs all
the required javascript calls via this new anchor tag. Use Lutz Roeder's
..NET Reflector to view the render method of the original TreeNode (or just
look at the DOM) to find out what javascript calls you should make when the
node is clicked on, etc.

To remove the node, you can just go up the family tree to the table that
contains both the new anchor tag and the old one and work your magic on that.
This method also allows you to scroll to a particular node -- just scroll to
the element with an ID of "a"+node.ValuePath!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top