possible to change toolbar item visibility from server side?

2 posts, 0 answers
  1. sf
    sf avatar
    103 posts
    Member since:
    Apr 2009

    Posted 21 Jul 2010 Link to this post

    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

  2. Petio Petkov
    Admin
    Petio Petkov avatar
    825 posts

    Posted 22 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top