select

Menu / Client-side Events

Rate this demo: Feedback
Run example in: C# VB.NET Change Skin:
Vista
  • BlackBlack
  • DefaultDefault
  • ForestForest
  • HayHay
  • Office2007Office2007
  • OutlookOutlook
  • SimpleSimple
  • SitefinitySitefinity
  • SunsetSunset
  • TelerikTelerik
  • VistaVista
  • Web20Web20
  • WebBlueWebBlue
  • Windows7Windows7

Example Source Code & Description

Instructions
Open in new window
  • RadMenu provides a number of client-side events that would allow you to accomplish even the most complicated tasks.

    You can attach to the RadMenu's events by using either the server-side properties or the client-side API.

    1. Attaching event handlers via a server-side property
      Each client-side event has a corresponding property, whose name is formed like OnClient[EventName].
      You can set the property to the name of the function to be called when the event occurs.
      <telerik:RadMenu ID="RadMenu1" runat="server" OnClientItemClicking="onClicking" />
      
      <script type="text/javascript">
      	function onClicking(sender, eventArgs) 
      	{ 
      		var item = eventArgs.get_item();
      		LogEvent("Clicking: " +item.get_text()); 
      		
      		var navigateUrl = item.get_navigateUrl();
      		if (navigateUrl && navigateUrl != "#") 
      		{ 
      			var proceed = confirm("Navigate to "+ navigateUrl + " ?"); 
      			if (!proceed) 
      			{ 
      				eventArgs.set_cancel(true);
      			} 
      		} 
      	} 
      </script>
      		
    2. Using the client-side API to attach event handlers
      Using the client-side API of RadMenu allows you to attach multiple event handlers to one event using the standard MS AJAX conventions.
      <script type="text/javascript">
      	function onClickedHandler1()
      	{
      		alert("First handler called");
      	}
      	function onClickedHandler2()
      	{
      		alert("Second handler called");
      	}
      
      	function pageLoad()
      	{
      		var menu = $find("<%=RadMenu1.ClientID%>");
      		
      		menu.add_itemClicked(onClickedHandler1);
      		menu.add_itemClicked(onClickedHandler2);
      	}
      </script>
      
      Another advantage of the client-side API is the possiblity of dynamically detaching certain handlers. You can use the remove_itemClicked method of the menu object.

      <script type="text/javascript">
      	$find(<%=RadMenu1.ClientID%>).remove_itemClicked(onClickedHandler1);
      </script>
      
    3. Cancelling an event
      The events, whose names end in ing, can be cancelled. You can cancel the event by using the set_cancel method of the event arguments passed to the handler.
      <script type="text/javascript">
      	function onClientItemClicking(sender, eventArgs)
      	{
      	    eventArgs.set_cancel(true);
      	}
      </script>
      	
Compatible with ASP.NET 2.0, 3.5 AJAX enabled Accessibility Verified!Valid XHTML 1.1! Optimized for Visual Studio 2005, 2008
Copyright 2002-2010 © Telerik. All right reserved  | 
Telerik Inc., 460 Totten Pond Rd, Suite 640, Waltham, MA 02451

www.telerik.com  |  Terms of Use  |  Contact Us