Menu Constructor

Note: This constructor is new in the .NET Framework version 2.0.

Initializes a new instance of the Menu class.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public Menu ()
public Menu ()
public function Menu ()

Use this constructor to create and initialize a new instance of the Menu class. To dynamically add a Menu control to a page, create a new Menu object, set its properties, and then add it to the Controls collection of a container control, such as PlaceHolder.

The following code example demonstrates how to use the constructor to dynamically add a Menu control to a page.

<%@ Page Language="C#" %>

<script runat="server">
  void Page_Load(Object sender, EventArgs e)
    // Create a new Menu control.
    Menu newMenu = new Menu();
    // Set the properties of the Menu control.
    newMenu.ID = "NavigationMenu";
    newMenu.DisappearAfter = 2000;
    newMenu.Orientation = Orientation.Vertical;
    newMenu.Target = "_blank";
    newMenu.StaticMenuItemStyle.ForeColor = System.Drawing.Color.Black;
    newMenu.DynamicMenuItemStyle.ForeColor = System.Drawing.Color.Gray;
    // Create the menu structure.
    // Create the root menu item.
    MenuItem homeMenuItem;
    homeMenuItem = CreateMenuItem("Home", "Home.aspx", "Home");
    // Create the submenu items.
    MenuItem musicSubMenuItem;
    musicSubMenuItem = CreateMenuItem("Music", "Music.aspx", "Music");
    MenuItem moviesSubMenuItem;
    moviesSubMenuItem = CreateMenuItem("Movies", "Movies.aspx", "Movies");
    // Add the submenu items to the ChildItems
    // collection of the root menu item.
    // Add the root menu item to the ItemsCollection 
    // of the Menu control.
    // Add the Menu control to the Controls collection
    // of the PlaceHolder control.
  MenuItem CreateMenuItem(String text, String url, String toolTip)
    // Create a new MenuItem object.
    MenuItem menuItem = new MenuItem();
    // Set the properties of the MenuItem object using
    // the specified parameters.
    menuItem.Text = text;
    menuItem.NavigateUrl = url;
    menuItem.ToolTip = toolTip;
    return menuItem;


    <form runat="server">
      <h3>Menu Constructor Example</h3>
      <asp:placeholder id="MenuPlaceHolder"


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions