Update RadTreeNode from another UserControl

6 posts, 0 answers
  1. Martin
    Martin avatar
    27 posts
    Member since:
    May 2011

    Posted 19 Nov 2012 Link to this post

    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.

  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 22 Nov 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Martin
    Martin avatar
    27 posts
    Member since:
    May 2011

    Posted 22 Nov 2012 Link to this post

    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?
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 27 Nov 2012 Link to this post

    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.
  6. Martin
    Martin avatar
    27 posts
    Member since:
    May 2011

    Posted 27 Nov 2012 Link to this post

    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.

    :-(
  7. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 30 Nov 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017