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

Creating new node in the tree using a web service

6 Answers 143 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michael Webb
Top achievements
Rank 1
Michael Webb asked on 24 Feb 2010, 11:41 PM
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.

6 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 25 Feb 2010, 12:19 PM
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.
0
Piyush Bhatt
Top achievements
Rank 2
answered on 25 Feb 2010, 04:20 PM
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.

0
Michael Webb
Top achievements
Rank 1
answered on 25 Feb 2010, 06:51 PM
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();
            this.node.expand();

            tree.trackChanges();
            this.node.get_nodes().add(node);

            tree.commitChanges();

            node.startEdit();
        }

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:

        [WebMethod]
        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.





0
Piyush Bhatt
Top achievements
Rank 2
answered on 25 Feb 2010, 07:57 PM
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.
0
Markus
Top achievements
Rank 2
answered on 20 Dec 2010, 05:12 PM
Hi

How can i repopulating on Serversiede?

Regards Markus
0
Simon
Telerik team
answered on 23 Dec 2010, 08:26 AM
Hello Markus,

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

Greetings,
Simon
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.
Tags
TreeView
Asked by
Michael Webb
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Piyush Bhatt
Top achievements
Rank 2
Michael Webb
Top achievements
Rank 1
Markus
Top achievements
Rank 2
Simon
Telerik team
Share this question
or