Creating new node in the tree using a web service

7 posts, 0 answers
  1. Michael Webb
    Michael Webb avatar
    2 posts
    Member since:
    Dec 2009

    Posted 24 Feb 2010 Link to this post

    I am trying to create a new node and add it to the tree using a web service. I have the client correctly calling the web service and I am creating a RadTreeNodeData and returning it from the server. However, I am not sure how to de-serialize the RadTreeNodeData on the client side so I can put it in the tree.

    Any help would be appreciated.
  2. Veronica
    Veronica avatar
    1213 posts

    Posted 25 Feb 2010 Link to this post

    Hello Michael Webb,

    Please take e look at  this Demo for populating RadTreeNodes with WebServices.

    If you need more help, please let me know.

    Sincerely yours,
    Veronica Milcheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 25 Feb 2010 Link to this post

    You shouldn't have to Deserialize anything as long as your Node's ExpandMode property is set to WebService. And Make sure the parameter name in your webservice method is [node]. I got error when the name was something else.

  5. Michael Webb
    Michael Webb avatar
    2 posts
    Member since:
    Dec 2009

    Posted 25 Feb 2010 Link to this post

    Thanks for pointing me to this demo. As I understand it, this works great when expanding. However, I am trying to solve the problem of a user creating a new node in the tree. Looking over the demo, I didn't see how this was accomplished. Here is what I am trying to do:

    1. User clicks on a right hand menu to create a new folder.
    2. I create a node client side, and add it to the tree, and then I call node.startEdit()

            function _createNewFolder() {
                if (this.node == null) return;

                var node = new Telerik.Web.UI.RadTreeNode();
                node.set_text("New Folder");

                var tree = this.node.get_treeView();




    I implement the onClientNodeEdited event, after the user picks the name, I invoke a web service to create the actual folder.
    On the server side, I create a RadTreeNodeData and populate it (at the same time actually creating the folder). I would like to return this RadTreeNodeData to the client and then have it loaded into the tree.

    This is my web method:

            public RadTreeNodeData CreateNewFolder(string id, string name)
                IPathElement element = GetElement(id);
                IPathElement child = element.CreateFolder(name);

                RadTreeNodeData nodeData = MakeNodeData(element);

                RadTreeNodeData data = new RadTreeNodeData();

                return data;

    This is my success handler from the web service call:

            function newFolder_success(result) {


    I should have a RadTreeNodeData at this point -- I'm just not sure how to update the temporary node I just created to invoke the Creation of the new folder.

  6. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 25 Feb 2010 Link to this post

    WebService call in Javascript is asynchronous. Hence after your node.expand() you cannot be sure that node.get_nodes() will return you the nodes from the web-service.

    First of all, after nodes.expand(), OnClientNodePopulating and OnClientNodePopulated will be called. Inside Populated() you can add a new TreeNode. And then you can do StartEdit. And within Edited() then you can call a PageMethod that will add folder as required. On the clientside since you have already added the node to tree, you won't have to do anything.

    But in case  you want to refresh the parent node to repopulate it, then you can clear the parent node's content, set its ExpandMode property back to WebService and then call expand() on it.
  7. Markus Wenzel
    Markus Wenzel avatar
    20 posts
    Member since:
    Dec 2009

    Posted 20 Dec 2010 Link to this post


    How can i repopulating on Serversiede?

    Regards Markus
  8. Simon
    Simon avatar
    2281 posts

    Posted 23 Dec 2010 Link to this post

    Hello Markus,

    Here is a demo showing all Load On Demand modes of RadTreeView. Please see the code of the implementation you need there.

    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017