With RadMenu for ASP.NET Ajax it is easy to add, remove or disable items at the client side. What is more, you can persist the changes after postback.
This example shows how to add/remove/disable items upon clicking on existing items.
In the OnClientItemClicked event:
var item = args.get_item();
//Creates a new item var childItem = new Telerik.Web.UI.RadMenuItem(); childItem.set_text("New" + item.get_text()); //Adds the newly created item to the items collection of the clicked item's parent item.get_parent().get_items().add(childItem);
var parentItem = item.get_parent(); //Removes the item from the items collection of the clicked item's parent parentItem.get_items().remove(item);
item.disable();
If you want to persist these changes after a postback the methods described below should be used:
var menu = $find("Menu1"); menu.trackChanges(); //add, remove, disable items menu.commitChanges();
foreach (ClientOperation<RadMenuItem> operation in RadMenu1.ClientChanges) { RadMenuItem item = operation.Item; switch (operation.Type) { case ClientOperationType.Insert: break; case ClientOperationType.Remove: break; case ClientOperationType.Update: UpdateClientOperation<RadMenuItem> update = operation as UpdateClientOperation<RadMenuItem>; break; case ClientOperationType.Clear: break; } }
www.telerik.com | Terms of Use | Contact Us