This is a migrated thread and some comments may be shown as answers.

Automatically put a node in Edit mode after postback

2 Answers 135 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bert Van der Auwera
Top achievements
Rank 1
Bert Van der Auwera asked on 07 Oct 2008, 09:34 AM
I've got a TreeView built up manually in code-behind by looping recursively through a custom XML document. Basically for each node in my XML document I create a new TreeView node and add it to the TreeView node collection, hierarchically. This works fine.

Clientside, I use a contextmenu to offer functionality to the user to build up the TreeView. One of those functions is called "Add a Subnode". What happens basically when clicking that function is a postback to the server where I create a new XML node in my custom document, at the right position based on the parameters and then reload the TreeView by calling the recursive function. This works fine.

What I'd like to do is the following: after adding a new subnode, automatically put the new node in edit mode when the page reloads so that the user can immediately start typing. Is there an easy way to do this? What I've come up with so far is registering a StartupScript or ScriptBlock that calls the following javascript function:

function editInit(nodeValue){
 var tree= $find("<%= RadTreeView1.ClientID %>"); 
 var node = tree.findNodeByValue(nodeValue); 
 tree._startEdit(node);
}

This does not work because I get javascript errors saying used methods are not supported on findNodeByValue due to the RadTreeView not being fully loaded yet. However, when i combine calling the editInit function with a setTimeout function (100 milliseconds), so that it waits a few milliseconds before calling the function, it works perfectly. However, I don't like this approach, because I don't know how reliable it's going to be once it's deployed online and the tree grows in size.

Isn't there an easier way to do this? Can't I set a property of a RadTreeNode which puts the node in Edit mode, the same way the property "Selected" works?

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 07 Oct 2008, 10:48 AM
Hello Bert Van der Auwera,

Please find attached a sample project demonstrating the approach.

Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bert Van der Auwera
Top achievements
Rank 1
answered on 07 Oct 2008, 11:44 AM
Thanks for the quick reply.

The way you registered the scriptpart makes it possible to access  the TreeView object and it's properties/functions without having to "artificially" insert some kind of delay in it.

Everything works as designed now, thanks once again!
Tags
TreeView
Asked by
Bert Van der Auwera
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Bert Van der Auwera
Top achievements
Rank 1
Share this question
or