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

possible to change toolbar item visibility from server side?

1 Answer 52 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
sf
Top achievements
Rank 1
sf asked on 21 Jul 2010, 09:35 AM
Is it possible to hide/show item(s) on toolbar based on the content user selected?
e.g. only 1 level of subfolder can be created, if user click on any level1 subfolder the Add Folder button will be hidden, if user click on a file in the root folder the delete button will be hidden

thanks in advance

1 Answer, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 22 Jul 2010, 02:29 PM
Hello,

You can control the toolbar visibility from client-side code. The code below illustrates how to achieve it.
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<head id="Head1" runat="server"
    <title></title
</head
<body
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager
    <script type="text/javascript">
        function configureToolbarItems(fileExplorer)
        {
            //Get a reference to the RadFileExplorer's toolbar
            var toolbar = fileExplorer.get_toolbar();
            //Get commands client-side objects
            var delCommand = toolbar.findItemByValue("Delete");
            var newFolderCommand = toolbar.findItemByValue("NewFolder");
              
            var treeView = fileExplorer.get_tree();
            var currentlySelectedNode = treeView.get_selectedNode();
            if(currentlySelectedNode.get_parent() == treeView)
            {
                //Disable Delete and Enable NewFolder
                delCommand.set_visible(false);
                newFolderCommand.set_visible(true);
            }
            else
            {
                //Enable Delete and Disble NewFolder
                delCommand.set_visible(true);
                newFolderCommand.set_visible(false);
            }
              
        }
          
        function ItemSelected(fileExplorer, args)
        {
            configureToolbarItems(fileExplorer);
        }
        function OnClientFolderChange(fileExplorer, args)
        {
            configureToolbarItems(fileExplorer);
        }
  
  
    </script>
    <div
        <telerik:RadFileExplorer ID="RadFileExplorer1" runat="server"
        OnClientItemSelected="ItemSelected"
        OnClientFolderChange = "OnClientFolderChange"
            <Configuration ViewPaths="~/Files" DeletePaths="~/Files" UploadPaths="~/Files"/> 
        </telerik:RadFileExplorer
    </div
    </form
</body
</html>
Also you can handle RadFileExplorer's OnItemCommand server-side event and make additional checks,e.g. 
protected void fileExplorer_ItemCommand(object sender, RadFileExplorerEventArgs e)
    {
        switch (e.Command)
        
            case "UploadFile":
                //DO SOMETHING
                break;
            case "CreateDirectory":
                //DO SOMETHING
                break;
            case "DeleteFile":
                //DO SOMETHING
                break;
        }
    }
Hope this helps.


Sincerely yours,
Petio Petkov
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
Tags
FileExplorer
Asked by
sf
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Share this question
or