Button appears disabled but is still clickable

5 posts, 0 answers
  1. Sheryl Landon
    Sheryl Landon avatar
    7 posts
    Member since:
    Mar 2006

    Posted 28 Jul 2008 Link to this post

    We are setting toolbar buttons to disabled depending on user actions, and the buttons do indeed appear disabled, but if clicked, the client-side function still executes.  Here is sample code for disabling a button - is there something more we need to do?

    var toolbar = $find(treeToolbarId);  
    toolbar.findItemByValue("DeleteItemButton").disable();  
     

    Thanks,
    Sheryl
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 29 Jul 2008 Link to this post

    Hi Sheryl,

    Are you using the latest version of RadControls for ASP.NET Ajax? I just checked the scenario with the attached page, but I did not have the error. Can you help me identify the problem if I am missing something?

    Best regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sheryl Landon
    Sheryl Landon avatar
    7 posts
    Member since:
    Mar 2006

    Posted 29 Jul 2008 Link to this post

    I have Telerik.Web.UI.dll version 2008.1.619.20... is that the latest?  I added your page to my project, and it also runs fine in my project, so I don't think the issue is the dll version.

    Differences in our code include
    1) we were using the <asp:scriptmanager> rather than the <telelrik:RadScriptManager>.  I changed this, no difference in button behavior.
    2) we have javascript functions specified in for the onclick attribute in each button, rather than a server-side function specified for OnButtonClick in the toolbar declaration.

    <telerik:RadToolBar ID="RadToolBar1" runat="server" OnButtonClick="RadToolBar1_ButtonClick">  
        <Items> 
            <telerik:RadToolBarButton Text="Button1" Value="Button1"</telerik:RadToolBarButton> 
            <telerik:RadToolBarButton Text="Button2" Value="Button2" ></telerik:RadToolBarButton> 
            <telerik:RadToolBarButton Text="Button3" Value="Button3" ></telerik:RadToolBarButton> 
            <telerik:RadToolBarButton Text="Button4" Value="Button4" ></telerik:RadToolBarButton> 
        </Items> 
    </telerik:RadToolBar> 
    vs
    <telerik:RadToolBar ID="TreeToolbar" Width="100%" Skin="Outlook" EnableViewState="false" runat="server">  
        <Items> 
            <telerik:RadToolBarButton ToolTip="Upload (Alt+U)" onClick="UploadFile()" CommandName="UploadFile" Value="UploadFile" ImageUrl="Images/upload.gif" Enabled='false' /> 
            <telerik:RadToolBarButton Tooltip="Create Folder" onClick="AddFolder()" CommandName="AddFolder" Value="AddFolder" ImageUrl="Images/addFolder.gif" Enabled='false' /> 
            <telerik:RadToolBarButton Tooltip="Delete Item" onClick="DeleteItem()" CommandName="DeleteItem" Value="DeleteItem" ImageUrl="Images/delete.gif" Enabled='false'/>         
            <telerik:RadToolBarButton Tooltip="View Item" onClick="ViewItem()" CommandName="ViewItem" Value="ViewItem" ImageUrl="Images/view.gif" Enabled='false' />   
            <telerik:RadToolBarButton Tooltip="Empty Recycle Bin" onClick="EmptyRecycleBin()" CommandName="EmptyRecycleBin" Value="EmptyRecycleBin" ImageUrl="Images/recycleBin.gif"  />    
     
        </Items> 
    </telerik:RadToolBar> 
     
    The latter seems to be the difference - I tried removing these and adding a single click handler to the toolbar tag and it worked.  How can I prevent the execution of the javascript function in the onclick attribute if the button is disabled? Is there another configuration to be set?  Or do I have to add code to each click handler to check an attribute of the button?
  5. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 31 Jul 2008 Link to this post

    Hi Sheryl,

    Thanks for the clarification!

    Indeed, the code you have will execute the same way with the latest version (2008.2.723) too. This comes, because the onclick attribute of the RadToolBarButton gets rendered to its HTML anchor element. Having that said, when you click on a button (even disabled), the javascrtipt function gets executed by the browser.

    You should instead use the client-side events of the RadToolBar, e.g.

    <script type="text/javascript"
        function onClientButtonClicked(sender, args) 
        { 
            var buttonCommandName = args.get_item().get_commandName(); 
            switch (buttonCommandName) 
            { 
                case "UploadFile": 
                    UploadFile(); 
                case "AddFolder": 
                    AddFolder(); 
    .... 
     
            } 
        } 
    </script> 
     
    <telerik:RadToolBar ID="TreeToolbar" Width="100%" Skin="Outlook" EnableViewState="false" runat="server" OnClientButtonClicked="onClientButtonClicked">   
        <Items>  
            <telerik:RadToolBarButton ToolTip="Upload (Alt+U)" CommandName="UploadFile" Value="UploadFile" ImageUrl="Images/upload.gif" Enabled='false' />  
            <telerik:RadToolBarButton Tooltip="Create Folder" CommandName="AddFolder" Value="AddFolder" ImageUrl="Images/addFolder.gif" Enabled='false' />  
            <telerik:RadToolBarButton Tooltip="Delete Item" CommandName="DeleteItem" Value="DeleteItem" ImageUrl="Images/delete.gif" Enabled='false'/>          
            <telerik:RadToolBarButton Tooltip="View Item" CommandName="ViewItem" Value="ViewItem" ImageUrl="Images/view.gif" Enabled='false' />    
            <telerik:RadToolBarButton Tooltip="Empty Recycle Bin" CommandName="EmptyRecycleBin" Value="EmptyRecycleBin" ImageUrl="Images/recycleBin.gif"  />     
      
        </Items>  
    </telerik:RadToolBar> 

    Let me know if that helps.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Jimmy Vithalani
    Jimmy Vithalani avatar
    22 posts
    Member since:
    Mar 2010

    Posted 03 Sep 2010 Link to this post

    Hi Erjan,

    At least there should be some way to find out in javascript if a RadToolbarButton is disabled or not.
     I have a javascript function attached to the button and dont want to place that code to click event of ToolBar, rather I would like to put an if on top of my function so if button is enabled then only I would move ahead.

    I see there is some function get_isEnabled(), how can I use it?

    Again one way for this I see is using RadToolBarButtonCollection get_Button() method but that accepts index which I dont want to passs as my toolbar is totally configurable and I don't know which button would come where, I can use Value to get the button.

    Thanks.
    Jimmy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017