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 API

Opening/Closing items
Item to open:  
Item to close:


Enabling/Disabling items
Item to disable:




  • RadMenu provides a flexible client-side API. You can easily interact with the menu in the browser using the menu client-side object.

    1. Getting the RadMenu client-side object. RadMenu creates a client-side object with the ClientID of the menu. You can obtain the reference using the following javascript code:
      var menu = $find(<%=RadMenu1.ClientID%>);		
      
    2. Once you get the client-side object of RadMenu, you can use the findItemByText / findItemByValue methods to get the instance of a particular item. Example:
      var menu = $find("<%=RadMenu1.ClientID%>");
      
      var text = $get("openTextBox").value; var item = menu.findItemByText(text);
    3. When you get the instance of a particular item, you can call the disable() / enable() / open() / close() / etc. methods:
      function openItem()
      {
      	var menu = $find("<%=RadMenu1.ClientID%>");
      	var text = $get("openTextBox").value;
      	
      	var item = menu.findItemByText(text);
      	
      	if (item)
      	{
      		item.open();
      	}
      	else
      	{
      		alert("Item with text '" + text + "' not found.");
      	}
      }
      
      function closeItem()
      {
      	var menu = $find("<%=RadMenu1.ClientID%>");
      
      var text = $get("closeTextBox").value; var item = menu.findItemByText(text); if (item) { item.close(); } else { alert("Item with text '" + text + "' not found."); } }

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page CodeFile="DefaultCS.aspx.cs" Language="c#" AutoEventWireup="true" Inherits="Telerik.Web.Examples.Menu.ClientSideAPI.DefaultCS" %>

    <%@ 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 runat="server">
        <qsf:HeadTag runat="server" ID="Headtag1"></qsf:HeadTag>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="C#" />

            <script type="text/javascript">
            //<!--
            function OpenItem()
            {
                var menu = $find("RadMenu1");
                var text = $get("openTextBox").value;
                
                var item = menu.findItemByText(text);
                
                if (item)
                {
                    item.open();
                }
                else
                {
                    alert("Item with text '" + text + "' not found.");
                }
            }
            
            function CloseItem()
            {
                var menu = $find("RadMenu1");
                var text = $get("closeTextBox").value;
                
                var item = menu.findItemByText(text);
                
                if (item)
                {
                    item.close();
                }
                else
                {
                    alert("Item with text '" + text + "' not found.");
                }
            }
            
            function DisableItem()
            {
                var menu = $find("RadMenu2");
                var text = $get("disableTextBox").value;
                
                var item = menu.findItemByText(text);
                
                if (item)
                {
                    item.disable();
                }
                else
                {
                    alert("Item with text '" + text + "' not found.");
                }
            }
            
            function EnableAll()
            {
                var menu = $find("RadMenu2");
                var items = menu.get_allItems();
                for (var i = 0; i < items.length; i++)
                {
                    items[i].enable();
                }
            }
            //-->
            </script>

            <fieldset style="margin-bottom:15px;padding:15px;">
                <legend>Opening/Closing items</legend>
                <br/>
                <div style="float: left; margin-top: 13px; margin-right: 80px;">
                    <telerik:RadMenu ID="RadMenu1" runat="server" EnableRoundedCorners="true" EnableShadows="true">
                        <Items>
                            <telerik:RadMenuItem Text="Corporate">
                                <Items>
                                    <telerik:RadMenuItem Text="About us">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Careers">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Services">
                                <Items>
                                    <telerik:RadMenuItem Text="Products">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Solutions">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Certifications">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Work">
                                <Items>
                                    <telerik:RadMenuItem Text="Clients">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Testimonials">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="FAQ">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                        </Items>
                    </telerik:RadMenu>
                </div>
                <div>
                    Item to open: &nbsp;<input type="text" id="openTextBox" value="Corporate" class="textfield"
                        style="vertical-align: top;" />
                    <button class="button" onclick="OpenItem();return false;" style="width: 70px">
                        Open</button><br />
                    Item to close:
                    <input type="text" id="closeTextBox" value="Corporate" class="textfield" style="vertical-align: top;" />
                    <button class="button" onclick="CloseItem();return false;" style="width: 70px">
                        Close</button><br />
                </div>
            </fieldset>
            <br />
            <br />
            <fieldset style="margin-bottom:15px;padding:15px;">
                <legend>Enabling/Disabling items</legend>
                <br/>
                <div style="float: left; margin-top: 13px; margin-right: 80px;">
                    <telerik:RadMenu ID="RadMenu2" runat="server" EnableRoundedCorners="true" EnableShadows="true">
                        <Items>
                            <telerik:RadMenuItem Text="Corporate">
                                <Items>
                                    <telerik:RadMenuItem Text="About us">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Careers">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Services">
                                <Items>
                                    <telerik:RadMenuItem Text="Products">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Solutions">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Certifications">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Work">
                                <Items>
                                    <telerik:RadMenuItem Text="Clients">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="Testimonials">
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="FAQ">
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                        </Items>
                    </telerik:RadMenu>
                </div>
                <div>
                    Item to disable:
                    <input type="text" id="disableTextBox" value="Corporate" class="textfield" style="vertical-align: top;" />
                    <button class="button" onclick="DisableItem();return false;" style="width: 70px">
                        Disable</button><br />
                    <button class="button" onclick="EnableAll();return false;" style="width: 70px">
                        Enable all</button><br />
                </div>
            </fieldset>
            <br style="clear: both" />
            <br />
            <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