RadControls for ASP.NET AJAX
RadToolBar's items can contain Buttons, DropDowns and SplitButtons. Each DropDown and SplitButton has its Buttons collection so that buttons can be added to these collections.
The RadToolBarButtonCollection object is returned by the get_buttons method of the RadToolBarDropDown or the RadToolBarSplitButton objects.The following table lists the most important methods.
Note |
|---|
Changes to the button collection made using these methods do not persist after a postback unless surrounded by a call to the trackChanges and the commitChanges methods of the toolbar object.
|
| Name | Parameters | Return Type | Description |
|---|
| add | RadToolBarButton | none | Adds a child button to the collection. |
CopyJavaScript
var toolBar = $find("<%=RadToolBar1.ClientID %>");
toolBar.trackChanges();
var dropDown = new Telerik.Web.UI.RadToolBarDropDown();
dropDown.set_text("DropDown");
var dropDownButton = new Telerik.Web.UI.RadToolBarButton();
dropDownButton.set_text("button1");
dropDown.get_buttons().add(dropDownButton);
var splitButton = new Telerik.Web.UI.RadToolBarSplitButton();
splitButton.set_text("Split Button");
var splitChildButton = new Telerik.Web.UI.RadToolBarButton();
splitChildButton.set_text("button1");
splitButton.get_buttons().add(splitChildButton);
toolBar.get_items().add(dropDown);
toolBar.get_items().add(splitButton);
toolBar.commitChanges();
| insert | int, RadToolBarButton | none | Inserts the button into the collection at the position defined by the first (index) parameter. |
CopyJavaScript
toolBar.trackChanges();
var dropDown = new Telerik.Web.UI.RadToolBarDropDown();
dropDown.set_text("DropDown");
var dropDownButton = new Telerik.Web.UI.RadToolBarButton();
dropDownButton.set_text("button1");
dropDown.get_buttons().insert(0, dropDownButton);
var splitButton = new Telerik.Web.UI.RadToolBarSplitButton();
splitButton.set_text("Split Button");
var splitChildButton = new Telerik.Web.UI.RadToolBarButton();
splitChildButton.set_text("button1");
splitButton.get_buttons().insert(0, splitChildButton);
toolBar.commitChanges();
| remove | RadToolBarButton | none | Removes the specified button from the collection. |
CopyJavaScript
toolBar.trackChanges();
var firstChildButton = dropDown.get_buttons().getButton(0);
dropDown.get_buttons().remove(firstChildButton);
var firstChildButton = splitButton.get_buttons().getButton(0);
splitButton.get_buttons().remove(firstChildButton);
toolBar.commitChanges();
| clear | none | none | Clears the Buttons collection of all the child buttons it contains. |
CopyJavaScript
toolBar.trackChanges();
dropDown.get_buttons().clear();splitButton.get_buttons().clear();
toolBar.commitChanges()
| getButton | int | RadToolBarButton | Returns the button from the collection that resides at the specified index. |
CopyJavaScript
var firstChildButton = dropDown.get_buttons().getButton(0);
var firstChildButton = splitButton.get_buttons().getButton(0);
| indexOf | RadToolBarButton | int | Returns the index of a button. |
CopyJavaScript
var firstChildButton = dropDown.get_buttons().getButton(0);
dropDown.get_buttons().indexOf(firstChildButton);
var firstChildButton = splitButton.get_buttons().getButton(0);
splitButton.get_buttons().indexOf(firstChildButton);
| removeAt | int | none | Removes the button at the specified index. |
CopyJavaScript
dropDown.get_buttons().removeAt(0);
splitButton.get_buttons().removeAt(0);
| get_count | none | int | Returns the number of the buttons in the collection. |
CopyJavaScript
dropDown.get_buttons().get_count();
splitButton.get_buttons().get_count();