RadToolBar provides a flexible client-side API - you can easily interact with the toolbar
in the browser using the toolbar client-side object.
- Getting the RadToolBar client-side object: RadToolBar creates a client-side object
with the ClientID of the toolbar. You can obtain the reference using the following
javascript code:
var toolBar = $find("<%=RadToolBar1.ClientID%>");
- Once you get the client-side object of RadToolBar, you can use the findItemByText
method to get the instance of a particular item. Example:
var toolBar = $find("<%= RadToolBar1.ClientID %>");
var text = $get("<%= TextBox1.ClientID %>").value;
var item = toolBar.findItemByText(text);
- When you get the instance of a particular item, you can call the disable()
/ enable() / etc. methods.
function toggleButton()
{
var toolBar = $find("<%= RadToolBar1.ClientID %>");
var text = $get("<%= TextBox1.ClientID %>").value;
var item = toolBar.findItemByText(text);
if (!item)
{
alert("There is no item with text \"" + text + "\"");
return false;
}
if (!Telerik.Web.UI.RadToolBarButton.isInstanceOfType(item))
{
alert("The item with the specified text is not a button.\nOnly buttons can be checked/unchecked");
return false;
}
if (Telerik.Web.UI.IRadToolBarDropDownItem.isInstanceOfType(item.get_parent()))
{
item.get_parent().showDropDown();
item.toggle();
}
return false;
}