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

[Solved] Refresh RadTreeView with AjaxRequestWithTarget()

2 Answers 386 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
HHalim
Top achievements
Rank 2
HHalim asked on 25 Jul 2007, 06:10 PM
Hello,
I'm trying to refresh RadTreeView using AjaxRequestWithTarget() call from javascript, however it does not refresh the tree. The javascript:
function RefreshTreeView() 
{ 
    var ajaxManager = <%= AjaxManager.ClientID %>;     
    ajaxManager.AjaxRequestWithTarget('<%= TreeView.UniqueID %>', ''); 
} 

The RefreshTreeView() function is being called from a ScriptManager.RegisterStartupScript inside an ajax hidden updatepanel. This happens when I close a RadDock object. I copied this script from the RadDock MyPortal example, except that I added the RefreshTreeView(). The intention is to remove a node from the tree when a dock object is closed.
The script is as follow:
                ScriptManager.RegisterStartupScript( 
                UpdatePanel, 
                this.GetType(), 
                "RemoveDock", 
                string.Format(@"function _removeDock() 
                    {{
                    Sys.Application.remove_load(_removeDock);
                    RefreshTreeView();
                    $find('{0}').undock();
                    $get('{1}').appendChild($get('{0}'));
                    $find('{0}').doPostBack('DockPositionChanged');
                    }};
                    Sys.Application.add_load(_removeDock);", 
                    ((RadDock)sender).ClientID, UpdatePanel.ClientID), 
                true); 
 

Please help, anyone?

Thanks
-H

2 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 27 Jul 2007, 09:47 AM
Hello Halim,

The reason for the problem is that ajax request updating RadTreeView is executed before  Ajax Request removing RadDock has finished. I suggest you replace your code registering the scripts with the following:
ScriptManager.RegisterStartupScript(  
                UpdatePanel1,  
                this.GetType(),  
                "RemoveDock",  
                string.Format(@"function _removeDock() {{  
    Sys.Application.remove_load(_removeDock);  
    $find('{0}').undock();  
    $get('{1}').appendChild($get('{0}'));  
    $find('{0}').doPostBack('DockPositionChanged');  
    window.setTimeout( function () {{ RefreshTreeView(); }}, 100 );  
}};  
Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID),  
                true); 

Also,I suggest you edit RefreshTreeView() method by this way:
 <script type="text/javascript">  
    function RefreshTreeView()    
    {    
        var ajaxManager = <%= AjaxManager.ClientID %>;        
        ajaxManager.AjaxRequestWithTarget('<%= TreeView.UniqueID %>', 'NodeClick#');  
    }    
    </script> 

If this does not help you,could you send us a small and running project that best exhibits the problem? We will test it locally and try to pinpoint the problem. Please attach the files to a new support thread and send them to us.

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
HHalim
Top achievements
Rank 2
answered on 27 Jul 2007, 09:19 PM
Thank you! Your solution does work. I'm amazed at what you guys can fix! :-)

I decided to not allowing user to delete from the dock command, the delay in refreshing the treeview may introduce error, and it's so slow anyway because the page has to re-create the dock objects in Page_Init.

Instead, I'll let user delete the node from the treeview and close the dock object through client javascript, this way it's faster and responsive.

Tags
Ajax
Asked by
HHalim
Top achievements
Rank 2
Answers by
Rosi
Telerik team
HHalim
Top achievements
Rank 2
Share this question
or