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

Clear Treeview nodes when window closes

3 Answers 87 Views
Window
This is a migrated thread and some comments may be shown as answers.
Antony
Top achievements
Rank 1
Antony asked on 20 May 2009, 01:36 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Fiko
Telerik team
answered on 20 May 2009, 03:34 PM
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.
0
Antony
Top achievements
Rank 1
answered on 21 May 2009, 08:23 AM
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
0
Fiko
Telerik team
answered on 21 May 2009, 01:44 PM
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.
Tags
Window
Asked by
Antony
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Antony
Top achievements
Rank 1
Share this question
or