How to add a custom button to the toolbar and hide an existing one(s)

7 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 18 Jan 2010 Link to this post

    Requirements

    RadControls version RadControls for ASP.NET AJAX 2009
    .NET version

    .NET20 & .NET35
    Visual Studio version

    2005/2008
    programming language

    C#
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    How to add a custom button to the toolbar and hide the Back and Forward buttons

    1. Create and add the custom button to the embedded RadToolBar control.
      • Server-side code:
        protected void Page_Load(object sender, EventArgs e)
        {
            RadToolBarButton propertyButton = new RadToolBarButton("Properties");
            propertyButton.Value = "PropertyButton";
            propertyButton.CssClass = "propertyBtnStyleClass";// Use CSS class in order to override the default values
           
            // The custom button will be the first button
            this.RadFileExplorer1.ToolBar.Items.Insert(0, propertyButton);
           
            // The custom button will be the last button
            //this.RadFileExplorer1.ToolBar.Items.Insert(this.RadFileExplorer1.ToolBar.Items.Count, propertyButton);
        }
      • Please note the assigned CssClass name. The implementation of the classs should be similar to:
        <style type="text/css">
            /* Set the desired properties to the custom button */
            a.propertyBtnStyleClass.rtbWrap .rtbText
            {
                font-size: 12px;
                background: url('ics.png') no-repeat left center;
            }
        </style>
    2. Hide Back and Forward buttons
      • This should be done in the Page's LoadCompleate event as shown bellow:
        protected override void OnLoadComplete(EventArgs e)
        {
            base.OnLoadComplete(e);
            HideToolBarButtons();
        }
      • The implementation of the HideToolBarButtons :
        private void HideToolBarButtons()
        {// Hides toolbar buttons
            this.RadFileExplorer1.ToolBar.Items.FindItemByValue("Back").Visible = false;
            this.RadFileExplorer1.ToolBar.Items.FindItemByValue("Forward").Visible = false;
        }
  2. Abdullah
    Abdullah avatar
    11 posts
    Member since:
    Oct 2011

    Posted 31 Jan 2012 Link to this post

    How can we handle these new added toolbar items in client side. If i want to change their enable state during runtime  when user click on a item in file explorer, how can i catch the toolbar items?
  3. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 02 Feb 2012 Link to this post

    Hi Abdullah,

    You can access the custom toolbar buttons on the client through RadFileExplorer's client-side object using the following approach:
    var toolbar = explorer.get_toolbar();//get reference to the toolbar
    var customButton = toolbar.findItemByValue("PropertyButton");//get reference to the button with Value=PropertyButton


    All the best,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  4. Steven
    Steven avatar
    2 posts
    Member since:
    Jun 2011

    Posted 11 Feb 2012 Link to this post

    I followed this and the sample program and have no problem putting up the alert window when the button is clicked.  But that is client side.  Is there a way I can get a postback to handle this server side?  Just like in this sample, I want to have the properties button launch a window where I can prompt for comments and other details about the file or directory.

    Thanks
  5. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 15 Feb 2012 Link to this post

    Hi Steven,

    In order to handle the button click on the server will require external ajaxification of RadFileExplorer, however, this is highly not recommended because RadFileExplorer's functionality is based on client-side callbacks and mixing it with ajax calls may cause unexpected errors.

    Could you please provide more detailed information on your specific scenario so we can try to provide suitable solution, if possible?

    Greetings,
    Dobromir
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Steven
    Steven avatar
    2 posts
    Member since:
    Jun 2011

    Posted 15 Feb 2012 Link to this post

    Basically what I would like is to be able to get the button click event with a postback, just as though I had created that toolbar myself, outside of the FileExplorer.  Inside that event handler, I would like to ask FileExplorer for the currently selected item so I could prompt the user for a Description and comments, and possibly even some security stuff.  I know this would be possible to do client-side with a lot of javascript, but we really like to keep our code in C# running on the server.
  7. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 16 Feb 2012 Link to this post

    Hi Steven,

    I believe this is not the correct example for your requirements. Please take a look at the following KB articles:
    Custom field in the GridContextMenu. Pass the selected item's path to the server when the field is clicked.
    Pass all of the selected items' paths to the server

    Regards,
    Dobromir
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top