Automatically put a node in Edit mode after postback

3 posts, 0 answers
  1. Bert Van der Auwera
    Bert Van der Auwera avatar
    2 posts
    Member since:
    Sep 2005

    Posted 07 Oct 2008 Link to this post

    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); 

    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. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 07 Oct 2008 Link to this post

    Hello Bert Van der Auwera,

    Please find attached a sample project demonstrating the approach.

    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Bert Van der Auwera
    Bert Van der Auwera avatar
    2 posts
    Member since:
    Sep 2005

    Posted 07 Oct 2008 Link to this post

    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!
Back to Top