Clear Treeview nodes when window closes

4 posts, 1 answers
  1. Antony
    Antony avatar
    57 posts
    Member since:
    Oct 2008

    Posted 20 May 2009 Link to this post

    Hi Everyone,

    I have been trying to accomplish something that should be rather simple.
    I have a RadWindow with a treeview that allows users to select items by checking nodes .
    When the RadWindow closes it is not destroyed so that next time they open the window the treeview does not need to reload but I want to uncheck all their previous selections.

    I can manage to do this using the following script in the ASPX code:

    var nodes = tree.get_checkedNodes();

     for (var i = 0; i < nodes.length; i++) {

     var node = nodes[i];

     node.set_checked(false);

     }

    This script is called when either the OK or Cancel button is clicked, but if the user clicks the "X" this script is not run.

    Also the rest of our application uses separate script files instead of embedding the javascript in the ASPX page.

    I have tried adding a beforeonclose event handler but that appears to be too late in the cycle.

    Please could someone suggest a way to accomplish this.


    many thanks
    Antony

  2. Answer
    Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 20 May 2009 Link to this post

    Hello Antony,

    I recommend you use the OnClientBeforeClose event of the RadWindow control. When the content page is loaded, you need to add the reference to the RadTreeView client-side object as a custom property of the RadWindow control. this can be done in the pageLoad event handler on the content page as follows :

    function pageLoad() 
        var treeView = $find("<%= RadTreeView1.ClientID %>"); 
        GetRadWindow().TreeView = treeView; 

    Then you can access the RadTreeView's object on the parent page as follows :

    <script type="text/javascript"
        function OnClientBeforeClose(oWindow, args) 
        { 
            var treeView = oWindow.TreeView; // get reference to the treeview
            var nodes = treeView.get_checkedNodes(); 
     
            for (var i = 0; i < nodes.length; i++) 
            { 
                var node = nodes[i]; 
                node.set_checked(false); 
            } 
        } 
    </script> 

    For your convenience I have attached a demo to the thread.
    I hope this helps.


    Greetings,
    Fiko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Antony
    Antony avatar
    57 posts
    Member since:
    Oct 2008

    Posted 21 May 2009 Link to this post

    Hi Fiko,

    Many thanks for your quick reply, your solution worked.

    I was doing something similiar except that I was registering the Treeview ClientID via the Scriptmanager and then attempting to $Find the treeview in the BeforeClose event.
    For some reason the registered variable would dissappear by the time the BeforeClose event occurred. I would really appreciate someone letting me know why as the RadWindow is not set to DestroyOnClose which means it was just hidden.

    Many thanks
    Antony
  4. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 21 May 2009 Link to this post

    Hello Antony,

    We are not quite sure that we understood you setup. Could you please provide more information about your configuration. It will be best if you paste some code snippets or open a new support ticket and send us a simple project. Once we have a better view over your setup we will do our best to provide a solution.

    Regards,
    Fiko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top