Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:25:37+00:00 2026-06-06T05:25:37+00:00

I have a one master Page. I want to add 3 Menu items to

  • 0

I have a one master Page. I want to add 3 Menu items to that page runtime.
How to add Parent menus and Child menus at runtime to master page?
In first 2 Menu items, there are 2 sub menu items. How can I do this?

The code is as follwos.

    public partial class MasterPage2 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
    LblDate.Text = DateTime.Today.ToString("dddd dd,MMM yyyy");
    lblusername.Text = Session["username"].ToString();
    if (Session["role"].ToString() == "1")
    {
        //Menu1.Items.Add(new MenuItem("System Information", "1", "", "~/home.aspx"));
        //Menu1.Items.Add(new MenuItem("Administration", "2", "", "~/home.aspx"));
        //Menu1.Items.Add(new MenuItem("Signout", "3", "", "~/Login.aspx"));

        //Menu1.FindItem("1").ChildItems.Add(new MenuItem("Search System Information", "", "", "~/SearchSystemInformation.aspx"));
        //Menu1.FindItem("1").ChildItems.Add(new MenuItem("Request New System", "", "", "~/RequestNewSystem.aspx"));

        //Menu1.FindItem("2").ChildItems.Add(new MenuItem("Manage System's Password", "", "", "~/SearchPasswordInformation.aspx"));
        //Menu1.FindItem("2").ChildItems.Add(new MenuItem("Manage Administrators", "", "", "~/ManageAdmins.aspx"));

        MenuItem ParentMenuItem = null;
        MenuItem ChildMenuItem = null;

        ParentMenuItem = CreateMenuItem("System Information", "~/home.aspx", "");

        ChildMenuItem = CreateMenuItem("Search System Information", "~/SearchSystemInformation.aspx", "");

        ParentMenuItem.ChildItems.Add(ChildMenuItem);

        ChildMenuItem = CreateMenuItem("Request New System", "~/RequestNewSystem.aspx", "");

        ParentMenuItem.ChildItems.Add(ChildMenuItem);

        Menu1.Items.Add(ParentMenuItem);

        ParentMenuItem = CreateMenuItem("Administration", "~/home.aspx", "");

        ChildMenuItem = CreateMenuItem("Manage System's Password", "~/SearchPasswordInformation.aspx", "");

        ParentMenuItem.ChildItems.Add(ChildMenuItem);

        ChildMenuItem = CreateMenuItem("Manage Administrators", "~/ManageAdmins.aspx", "");

        ParentMenuItem.ChildItems.Add(ChildMenuItem);

        Menu1.Items.Add(ParentMenuItem);

        ParentMenuItem = CreateMenuItem("Signout", "~/Login.aspx", "");
        Menu1.Items.Add(ParentMenuItem);

        //MenuItem mnuSystemInfo = new MenuItem();
        //mnuSystemInfo.NavigateUrl = "~/Home.aspx";
        //mnuSystemInfo.Text = "System Information";
        ////Menu1.Items.Add(mnuSystemInfo);

        //MenuItem mnuSearchSystemInfo = new MenuItem();
        //mnuSearchSystemInfo.NavigateUrl = "~/SearchSystemInformation.aspx";
        //mnuSearchSystemInfo.Text = "Search System Information";
        //mnuSystemInfo.ChildItems.Add(mnuSearchSystemInfo);
        //Menu1.Items.Add(mnuSystemInfo);
        //Menu1.Items.Add(mnuSearchSystemInfo);




    }
    else if(Session["role"].ToString()=="2")
    {
        //Menu1.Items.Clear();
        //Menu1.Items.Add(new MenuItem("System Information", "1", "", ""));
        //Menu1.Items.Add(new MenuItem("Signout", "3", "", ""));

        //Menu1.FindItem("1").ChildItems.Add(new MenuItem("Search System Information", "", "", "~/SearchSystemInformation.aspx"));
        //Menu1.FindItem("1").ChildItems.Add(new MenuItem("New System Request", "", "", "~/RequestNewSystem.aspx"));
    }
}

MenuItem CreateMenuItem(String text, String url, String toolTip)
{
    // Create a new MenuItem object.
    MenuItem menuItem = new MenuItem();

    menuItem.Text = text;
    menuItem.NavigateUrl = url;
    menuItem.ToolTip = toolTip;
    return menuItem;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:25:40+00:00Added an answer on June 6, 2026 at 5:25 am

    You can add Nodes to Menu dynamically in Code behind:

    MenuItem mnuTest = new MenuItem();
    mnuTest.NavigateUrl = "";
    mnuTest.Text = "Test";
    Menu1.Items.Add(mnuTest); 
    

    You can add Child nodes to Menu as:

    MenuItem mnuTest = new MenuItem(); 
    mnuTest.NavigateUrl = ""; 
    mnuTest.Text = "Test"; 
    
    
    MenuItem mnuTestChild = new MenuItem(); 
    mnuTestChild.NavigateUrl = ""; 
    mnuTestChild.Text = "Child Test"; 
    mnuTest.ChildItems.Add(mnuTestChild); 
    Menu1.Items.Add(mnuTestChild);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two pages that inherit from one master page, First.aspx or second.aspx. Navigation
I have a master page, there's only one menu item and a contentplaceholder there.
suppose i have one dowpdown in master page and i want that when user
I have one master page which applies to all pages in this website. On
I am working on asp.net using c#. I have one master page with 3
I am working with an ASP.NET MVC application. I have one master page having
In VS 2008, I have an ASP.NET content page having one master page. I
I have a Master Page which has an associated css file. On one of
Suppose I have a Site.Master page. I want to display something like the version
I have a custom control in my mater page that represents a menu, let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.