Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Menu / Client-side Events


  • 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>
      	

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page CodeFile="DefaultVB.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="Telerik.Web.Examples.Menu.ClientEvents.DefaultVB" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <qsf:HeadTag runat="server" ID="Headtag1"></qsf:HeadTag>
        <link rel="stylesheet" type="text/css" href="styles.css" />

        <script type="text/javascript">
        //<![CDATA[
            function onMouseOver(sender, eventArgs)
            {
                logEvent("Mouse over: " + eventArgs.get_item().get_text());    
            }
            
            function onMouseOut(sender, eventArgs)
            {
                logEvent("Mouse out: " + eventArgs.get_item().get_text());    
            }
            
            function onClicking(sender, eventArgs)
            {
                var item = eventArgs.get_item();
                logEvent("On clicking: " + item.get_text());                
                
                var navigateUrl = item.get_navigateUrl();
                if (navigateUrl && navigateUrl != "#")
                {
                    var proceed = confirm("Navigate to "+ navigateUrl + " ?");
                    eventArgs.set_cancel(!proceed);
                }
            }
                        
            function onClicked(sender, eventArgs)
            {
                logEvent("On clicked: " + eventArgs.get_item().get_text());
            }
            
            function onOpening(sender, eventArgs)
            {
                logEvent("On opening: " + eventArgs.get_item().get_text());
            }
            
            function onClosing(sender, eventArgs)
            {
                logEvent("On closing: " + eventArgs.get_item().get_text());
            }
            function onOpened(sender, eventArgs)
            {
                logEvent("On opened: " + eventArgs.get_item().get_text());
            }
            
            function onClosed(sender, eventArgs)
            {
                logEvent("On closed: " + eventArgs.get_item().get_text());
            }
            
            function onFocus(sender, eventArgs)
            {
                logEvent("On focus: " + eventArgs.get_item().get_text());
            }
            
            function onBlur(sender, eventArgs)
            {
                logEvent("On blur: " + eventArgs.get_item().get_text());
            }
            
            function clearLog()
            {
                var log = $get("EventLog");
                
                log.value = "";
            }
        //]]>
        </script>

    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="VB" />
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1">
                <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Logged events">
                    <ul style="margin-left: 0; border-left: none">
                        <li>
    <asp:CheckBox ID="MouseOver" runat="server" Text="OnClientMouseOver" AutoPostBack="True"
    Checked="True" OnCheckedChanged="MouseOver_CheckedChanged" />

                        </li>
                        <li>
    <asp:CheckBox ID="MouseOut" runat="server" Text="OnClientMouseOut" AutoPostBack="True"
    Checked="True" OnCheckedChanged="MouseOut_CheckedChanged"></asp:CheckBox>

                        </li>
                        <li>
    <asp:CheckBox ID="ItemClicking" runat="server" Text="OnClientItemClicking" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemClicking_CheckedChanged"></asp:CheckBox>

                        </li>
                        <li>
    <asp:CheckBox ID="ItemClicked" runat="server" Text="OnClientItemClicked" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemClicked_CheckedChanged"></asp:CheckBox>

                        </li>
                    </ul>
                    <ul>
                        <li>
    <asp:CheckBox ID="ItemOpening" runat="server" Text="OnClientItemOpening" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemOpening_CheckedChanged"></asp:CheckBox>

                        </li>
                        <li>
    <asp:CheckBox ID="ItemOpened" runat="server" Text="OnClientItemOpened" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemOpened_CheckedChanged"></asp:CheckBox>

                        </li>
                        <li>
    <asp:CheckBox ID="ItemClosing" runat="server" Text="OnClientItemClosing" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemClosing_CheckedChanged"></asp:CheckBox></li>

                        <li>
    <asp:CheckBox ID="ItemClosed" runat="server" Text="OnClientItemClosed" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemClosed_CheckedChanged"></asp:CheckBox></li>

                    </ul>
                    <ul>
                        <li>
    <asp:CheckBox ID="ItemFocus" runat="server" Text="OnClientItemFocus" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemFocus_CheckedChanged"></asp:CheckBox></li>

                        <li>
    <asp:CheckBox ID="ItemBlur" runat="server" Text="OnClientItemBlur" AutoPostBack="True"
    Checked="True" OnCheckedChanged="ItemBlur_CheckedChanged"></asp:CheckBox></li>

                    </ul>
                </qsf:ConfiguratorPanel>
                <telerik:RadMenu ID="RadMenu1" runat="server" OnClientMouseOver="onMouseOver" OnClientMouseOut="onMouseOut"
                    OnClientItemClicking="onClicking" OnClientItemClicked="onClicked" OnClientItemOpened="onOpened"
                    OnClientItemOpening="onOpening" OnClientItemFocus="onFocus" OnClientItemBlur="onBlur"
                    OnClientItemClosed="onClosed" OnClientItemClosing="onClosing" DataSourceID="SiteMapDataSource1"
                    Style="margin: 0 0 100px 0; float: none;"
                    EnableRoundedCorners="true" EnableShadows="true">
                </telerik:RadMenu>
                <asp:SiteMapDataSource runat="server" ID="SiteMapDataSource1" ShowStartingNode="false" />
                <qsf:EventLogConsole runat="server" ID="EventLogConsole1" AllowClear="true" />
            </telerik:RadAjaxPanel>
            <qsf:Footer ID="Footer1" runat="server" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451