Skip to main content

Practical-15

Problem Statement

Write a program using Menu Control.

Solution

To create a program using Menu Control in ASP.NET, follow the steps below:

  1. Create a new ASP.NET Web Application project in Visual Studio.
  2. Add a new Web Form to the project by right-clicking on the project in the Solution Explorer, selecting "Add" > "Web Form".
  3. Rename the Web Form to "Default.aspx".
  4. Open the "Default.aspx" file and design the user interface as per your requirements using HTML and ASP.NET controls.
  5. Add the following controls to the "Default.aspx" form:
    • Menu control: <asp:Menu ID="menuControl" runat="server" Orientation="Horizontal"></asp:Menu>
  6. In the code-behind file, write the following code in the Page_Load event handler to populate the Menu control:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MenuItem homeItem = new MenuItem("Home");
MenuItem aboutItem = new MenuItem("About");
MenuItem contactItem = new MenuItem("Contact");

menuControl.Items.Add(homeItem);
menuControl.Items.Add(aboutItem);
menuControl.Items.Add(contactItem);
}
}
  1. Build and run the application to see the Menu control in action.

This completes the solution for creating a program using Menu Control in ASP.NET.