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

Events on the tree stops working after folder rename/move/delete/..

2 Answers 58 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 05 Oct 2010, 03:04 PM

When the file explorer is loaded I add handlers to intercept context menu handling for the tree view part (I enable/disable menu options). This is hooked up like this

 

In a user control:

<telerik:RadFileExplorer  ...  OnClientLoad="EXPLORER.attachHandlers" 

 

the javascript:

var EXPLORER =    {

        attachHandlers: function (explorer, args) {

               var tree = explorer.get_tree();

               tree.add_contextMenuItemClicking(EXPLORER.treeContextMenuClicking);

               tree.add_contextMenuShowing(EXPLORER.treeContextMenuShowing);

   },

 

The functions treeContextMenuShowing and is now run every time I right click a folder  in the tree and treeContextMenuClicking  is run when I click a menu context menu item.

 

However, those functions isn't called on user interaction anymore after I've done an "updating command", like renamed a folder or created a new folder via the context menu in the tree view. The events stops firing for all the folder nodes in the tree, not only the one(s) I've updated.

 

I also has showing and click events hooked up for the grid context menu, and they keep working after I do updates to the items in the grid. So the problem is local to the tree.

 

What do I do to fix this?

Thank you,

Best regards,

Andreas Nilsson

2 Answers, 1 is accepted

Sort by
0
Accepted
Dobromir
Telerik team
answered on 06 Oct 2010, 04:41 PM
Hi Andreas,

This is an expected behavior of RadFileExplorer. The refresh of the RadFileExplorer is an AJAX request, during this request the TreeView client-side object is recreated, thus all event handlers registered during the RadFileExplorer OnLoad event are lost. In order to avoid this issue you need to re-attach the custom handlers in the OnAjaxResponseEnd event of the UpdatePanel, e.g.:
<telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientLoad="OnClientLoad">
    <Configuration ViewPaths="~/ROOT" DeletePaths="~/ROOT" UploadPaths="~/ROOT" />
</telerik:RadFileExplorer>
 
<script type="text/javascript">
    function OnClientLoad(sender, args)
    {
        var tree = sender.get_tree();
        tree.add_contextMenuShowing(function () { alert(1); });
        tree.add_contextMenuItemClicking(function () { alert(2); });
    }
 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function ()
    {
        setTimeout(function ()
        {
            var fileExplorer = $find("<%=RadFileExplorer1.ClientID%>");
            var tree = fileExplorer.get_tree();
 
            tree.add_contextMenuShowing(function () { alert(1); });
            tree.add_contextMenuItemClicking(function () { alert(2); });
        }, 0);
    });
</script>

I hope this helps.

Greetings,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andreas
Top achievements
Rank 1
answered on 15 Oct 2010, 03:09 PM
Thank you Dobomir, it worked.

However, I find it a bit odd that it is considered "standard behavior" that the tree view is recreated. The grid is also seemingly reloaded with data, but it manages to keep its events. It is not that obvious that the tree view is recreated, but the grid is not.
Tags
FileExplorer
Asked by
Andreas
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or