RadControls for ASP.NET AJAX
Common API
Both the RadMenu and the RadContextMenu client-side objects have many of the same methods. The following table lists the most important of these common client-side methods:
Name | Parameters | Return Type | Description |
|---|
trackChanges | none | none |
Begins tracking changes to the menu items. Only changes to the items that occur between a call to trackChanges and commitChanges persist after a postback.
|
commitChanges | none | none |
Ends tracking changes to the menu items. Only changes to the items that occur between a call to trackChanges and commitChanges persist after a postback.
|
Note |
|---|
Client side changes are available on the server side after postback. You can use the ClientChanges property to access them.
|
CopyJavaScript
function AddNewItem()
{
var menu = $find("<%= RadMenu1.ClientID %>");
var menuItem = new Telerik.Web.UI.RadMenuItem();
menuItem.set_text("New Item");
menu.trackChanges();
menu.get_items().add(menuItem);
menu.commitChanges();
}
disable | none | none | Disables all items in the menu. Clicking on any item has no effect, child items cannot be opened. |
CopyJavaScript
function DisableMenu()
{
var menu = $find("<%= RadMenu1.ClientID %>");
menu.disable();
}
enable | none | none | Enables all items in the menu. |
CopyJavaScript
function EnableMenu()
{
var menu = $find("<%= RadMenu1.ClientID %>");
menu.enable();
}
get_enabled | none | boolean | True if the menu is enabled. To enable a menu, use the enable() method. |
close | none | none | Closes all opened items |
findItemByValue | (string value) | RadMenuItem |
Returns the first RadMenuItem object whose Value property is equal to the passed parameter.
|
findItemByText | (string text) | RadMenuItem |
Returns the first RadMenuItem object whose Text property is equal to the passed parameter.
|
findItemByUrl | (string URL) | RadMenuItem |
Returns the first RadMenuItem object whose NavigateUrl property is equal to the passed parameter.
|
findItemByAbsoluteUrl | (string URL) | RadMenuItem |
Returns the first RadMenuItem object whose NavigateUrl property is equal to the passed parameter. Note that the parameter should ends with '/' like:
var item = sender.findItemByAbsoluteUrl('http://www.test.com/'); |
findItemByAttribute | (string attributeName, string value) | RadMenuItem |
Returns the first RadMenuItem object with a custom attribute of the specified name that has the specified value.
|
get_items | none | RadMenuItemCollection | Returns the collection of root level items. |
CopyJavaScript
function showRootItems()
{
var menu = $find("<%= RadMenu1.ClientID %>");
var items = menu.get_items();
for (var i=0; i < items.get_count(); i++)
{
alert(items.getItem(i).get_text());
}
}
get_allItems | none | Array | Gets a linear collection of all items. This includes all root and child items in the menu. |
CopyJavaScript
function showAllItems()
{
var menu = $find("<%=RadMenu1.ClientID %>");
for (var i=0; i< menu.get_allItems().length; i++)
{
alert(menu.get_allItems()[i].get_text());
}
}
focus | none | none | Brings the focus to the menu so that it can be controlled via the keyboard. |
get_focusedItem | none | RadMenuItem | Returns the focused root level item. Null if no item has focus. |
get_openedItem | none | RadMenuItem | Returns the opened root level item. If no item is opened at the root level returns null. |
get_selectedItem | none | RadMenuItem | Returns the selected menu item. If no item is selected returns null. |
get_attributes | none | Collection | Returns the collection of custom attributes for the menu. |
get_clicked | none | Boolean | True if the user has clicked on a root menu item to expand it when ClickToOpen is True. |
set_clicked | Boolean | none |
Sets whether the user has clicked on a root menu item to expand it when ClickToOpen is True. See example here.
|
get_contextMenuElement | none | HTML Element | Gets the DOM element for the menu. |
CopyJavaScript
function hidemenu()
{
var menu = $find("<%= RadMenu1.ClientID %>");
menu.get_element().style.display = "none";
}
function showmenu()
{
var menu = $find("<%= RadMenu1.ClientID %>");
menu.get_element().style.display = "";
}
get_childListElement | none | HTML Element | Gets the DOM element for the list of items in the menu. |
enableEvents | none | none |
Enables the control client-side event emitting. Events are enabled by default.
|
disableEvents | none | none | Disables the control client-side event emitting. |
add_<EventName> | (mixed eventHandler) | none |
Attaches an eventHandler to the event with the name <EventName>. Note that client-side event names differ from their server-side counterparts. For more information, see Client-Side Events.
|
CopyJavaScript
function OnClientItemBlurHandler()
{
alert( "goodbye");
}
function AttachBlurHandler()
{
var menu = $find("<%=RadMenu1.ClientID %>");
menu.add_itemBlur(OnClientItemBlurHandler);
}
remove_<EventName> | (mixed eventHandler) | Boolean |
Detaches an eventHandler from the event with the name <EventName>.Returns "True" if the eventHandler is found and detached, false otherwise.Note that client-side event names differ from their server-side counterparts. For more information, see Client-Side Events.
|
CopyJavaScript
function OnClientItemBlurHandler()
{
alert( "goodbye");
}
function DetachBlurHandler()
{
var menu = $find("<%=RadMenu1.ClientID %>");
menu.remove_itemBlur(OnClientItemBlurHandler);
}
RadContextMenu-specific API
The RadContextMenu client-side object has some additional methods that are specific to it:
Name | Parameters | Return Type | Description |
|---|
show | (event) | none | Displays the menu as a pop-up, using the position in the DOM event that is passed as a parameter. |
showAt | (int X, int Y) | none | Displays the menu as a pop-up at the coordinates specified by the parameters. |
Note |
|---|
When calling showAt from in response to a client-side event, it is a good idea to call $telerik.cancelRawEvent(event) afterwards in order to prevent the default event processing from hiding the context menu you just displayed.
|
hide | none | none | Hides the menu. |
get_targets | none | Array | Returns the array of targets to which the context menu is attached. Each target identifies an element or family of elements that cause the menu to appear when right-clicked. |
addTargetElement | element | none | Attaches the context menu to the specified target element. |
removeTargetElement | element | none | Detaches the context menu from the specified target element. |
RadContextMenu static objects and methods
The Telerik.Web.UI.RadContextMenu.contextMenus holds a static collection with references to all RadContextMenus on the page.
CopyJavaScript
function iterateThroughAllContextMenus()
{
var contextMenus = Telerik.Web.UI.RadContextMenu.contextMenus;
for (var contextMenuId in contextMenus)
{
var contextMenu = contextMenus[contextMenuId];
...
}
}
The Telerik.Web.UI.RadContextMenu.hideAll method hides all visible RadContextMenus on the page.
addTargetElement(element), removeTargetElement(element) methods to dynamically add/remove targets to the context menu.
See Also