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

Update RadTreeNode from another UserControl

5 Answers 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 19 Nov 2012, 09:15 AM
Hi,

I´m building a master/content page with a treeview for navigation to the left and then clicking on nodes, different usercontrols are loaded (visible true/false) in the content pane. When data has been updated in the content user control, the treeview nodes text should be changed. For example when I click a "department" node, the different textboxes for the department is loaded to the right. If the name was changed, the treeview node text should be updated.

Today I do this with events from the UserControl but it seems like a lot of overhead (using AJAX) for just updating the text-property of the treenode. So Im tryiing to achieve this using Client-Side code. The problem is that I dont know how to reach the selected node from javascript inside the UserControl. If I when the save button is clicked calls a method (javascript) in the main page. But that method cannot reach the textbox in the user control instead.

Help is much appreciated.

5 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 22 Nov 2012, 09:31 AM
Hi Martin,

I have prepared a sample project for you, in order to demonstrate you the correct approach. In the provided sample are implemented both server-side and client side approach for accessing the RadTreeView and altering the selected Node's text. Please find the sample attached.


All the best,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Martin
Top achievements
Rank 1
answered on 22 Nov 2012, 12:43 PM
Thank you SO much!

This is almost exactly what I needed so again, thank you! Just one missing piece. When I hit the button (in my case the Save button), In the same script, I want to be able to refresh the child nodes of the selected node. The problem is that post-backing on the server (and save to database) occurs after the OnClick-event which means the selected node will refresh its child nodes (using collapse/expand with expandmode = webservice) BEFORE the database changes has been made resulting in wrong child nodes displaying...

Is there any way around this except with a client side delay?

Another thing, heres my script:

function OnClientClicked(sender, eventArgs) {
             var treeview = $find("ctl00_MainContent_RadTreeView1");
             var value = document.getElementById('<%=txtClientName.ClientID%>').value;
 
             var selectedNode = treeview.get_selectedNode();
 
             selectedNode.collapse();
             selectedNode.get_treeView().trackChanges();
             selectedNode.set_text(value);
             selectedNode.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);
             selectedNode.get_nodes().clear();
             selectedNode.get_treeView().commitChanges();
             selectedNode.expand();
         }

I want the script to:
1. Collapse the selected node
2. Change the text to new value
3. Clear child nodes (since they might have changed)
4. Expand node again triggering webservice expand and reload of nodes.

This does not work. If I remove the clearing of the child nodes I can see that the node expands again. But it does not seem to be possible to expand a webservice node clien-side?
0
Nencho
Telerik team
answered on 27 Nov 2012, 12:35 PM
Hello Martin,

I can suggest you to refer to this forum thread, where the implementation of the desired functionality is described in details.

Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Martin
Top achievements
Rank 1
answered on 27 Nov 2012, 02:21 PM
Hello, 

I copied the code and changed from changing the root node to changing the selected node but the page hangs when wiring "return refresh()" to the button.

:-(
0
Nencho
Telerik team
answered on 30 Nov 2012, 01:35 PM
Hello Martin,

Could clarify a bit more about the issue you had faced, when implementing the suggested approach from the specified forum thread?


Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Martin
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Martin
Top achievements
Rank 1
Share this question
or