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

JS: How to disable all?

3 Answers 133 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Runat="Server"
Top achievements
Rank 2
Runat="Server" asked on 08 Nov 2011, 06:45 PM
How to disable all items of ToolBar in client side include separators, templates and buttons ets?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Nov 2011, 06:14 AM
Hello Runat="Server",

You can try the following javascript.
JS:
<script type="text/javascript">
function OnClientClick()
 {
    var toolBar = $find("<%= RadToolBar1.ClientID %>");
    var items = toolBar.get_items();
    for (var i = 0; i < items.get_count(); i++)
     {
       var itm=  items.getItem(i);
       itm.set_enabled(false);
     }
 }
</script>

Thanks,
Princy.
0
Runat="Server"
Top achievements
Rank 2
answered on 09 Nov 2011, 07:08 AM
Hello,

This only works for simple buttons.

If we use a <ItemTemplate> with an internal RadMenu with sub RadMenu
or code HTML inside <ItemTemplate>, nothing happens!

The content of ToolBar is generated dynamically. So, find all itemtemplates and buttons one-by-one for disable/enable - the bad way!

I need to block all the tools, if user is out of system. After login must to enable toolbar. When user is log out, then change toolBar to disable mode  ( switch - enable/disable) .

Problem!
0
Kate
Telerik team
answered on 14 Nov 2011, 10:13 AM
Hello Arie,

Besides the approach that Princy has suggested you will also need to find the different controls in the RadToolbar and disable them as well.  You can use the following code for instance:
function OnClientLoad() {
    var toolBar = $find("<%= toolbar1.ClientID %>"); 
    var tbutton = toolBar.findItemByValue("value1")
    var button = tbutton.findControl("Button1"); //for RadControls
    alert(button);
    var button1 = $telerik.findElement(tbutton.get_element(), ("btn"));
           //to find a generic HTML element
    alert(button1);
}

markup:
<telerik:RadToolBar ID="toolbar1" AutoPostBack="true" Width="100%" runat="server"
            OnClientLoad="OnClientLoad" >
            <Items>
            <telerik:RadToolBarButton Text="LeaveButton" Value="leaveButton1">
                </telerik:RadToolBarButton>
                <telerik:RadToolBarButton Value="value1">
                    <ItemTemplate>
                        <telerik:RadButton ID="Button1" runat="server" Text="Button" />
                        <asp:Button ID="btn" Text="Leave" runat="server" />
                    </ItemTemplate>
                </telerik:RadToolBarButton>
            </Items>
        </telerik:RadToolBar>

All the best,
Kate
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
Tags
ToolBar
Asked by
Runat="Server"
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Runat="Server"
Top achievements
Rank 2
Kate
Telerik team
Share this question
or