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

Button appears disabled but is still clickable

4 Answers 770 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Sheryl Landon
Top achievements
Rank 1
Sheryl Landon asked on 28 Jul 2008, 07:56 PM
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

4 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 29 Jul 2008, 08:37 AM
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.
0
Sheryl Landon
Top achievements
Rank 1
answered on 29 Jul 2008, 05:50 PM
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?
0
Erjan Gavalji
Telerik team
answered on 31 Jul 2008, 02:44 PM
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.
0
Jimmy Vithalani
Top achievements
Rank 1
answered on 03 Sep 2010, 02:34 PM
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.
Tags
ToolBar
Asked by
Sheryl Landon
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
Sheryl Landon
Top achievements
Rank 1
Jimmy Vithalani
Top achievements
Rank 1
Share this question
or