You must Sign In to post a response.
  • Category: ASP.NET

    Get the text of menu item

    How to get the text of menu item(Created in Master page) in content page?
  • #768248
    Hi,
    Try this code in ContentPage.cs:


    Menu masterMenu = (Menu) Master.FindControl("IdOfMenuCtrlOnMaster");
    if (masterMenu != null)
    {
    string Itemtext = masterMenu.SelectedItem.Text;
    }

  • #768283
    You can use given code snippets as example to get the text of menu item.
    Example 1
    protected void Page_Load(object sender, EventArgs e)
    {
    Menu Menu = (Menu)Page.Master.FindControl("NavigationMenuAdmin");
    Menu.MenuItemClick +=Menu_MenuItemClick;
    }

    void Menu_MenuItemClick(object sender, MenuEventArgs Events)
    {
    Menu Menu = (Menu)sender;
    MenuItem selectedItem = Menu.SelectedItem;
    Response.Write("Selected Item is: " + Menu.SelectedItem.Text + ".");
    }


    Example 2
     using System.Web.UI.WebControls;

    protected void YourMenuName_MenuItemClick(object sender, MenuEventArgs e)
    {
    YourMenuItem selectedItem = YourMenuName.SelectedItem;
    Label1.Text = YourMenuName.SelectedItem.Text ;
    }


  • Sign In to post your comments