Creating a Reusable Navigation Menu

Nearly all web sites and web applications on the internet today have some form of user friendly navigation system that allows you to jump from page to page with ease from any location in the website. Most interface developers know how cumbersome it is to place this navigation menu on every single page in the website. Moreover, when something in the navigation changes such as a page name or title, every instance of the menu needs to be updated across all pages.

Dreamweaver developers are probably familiar with the use of templates to solve this recurring problem, whereby a single template for the menu may be defined and then placed onto the web pages requiring the navigation menu. You can then manage a single template and when you make changes, those changes are automatically propagated across all web pages using that template.

VS.NET developers have access to a similar style of implementation, but its design is slightly more object oriented. It also takes advantage of the code-behind pattern, where a front end HTML designer can implement an interface separately from the server side code.

In this tutorial we’ll examine this reusable pattern called a Web User Control, and implement a simple demonstration of how this user control can be used to construct a navigation menu component that can be placed on any page in your web application.

Note: This tutorial is designed using VB.NET and Visual Studio .NET 2003
In order for the source files to work they must be installed in the correct virtual directory; http://localhost/DNZone/MyNav

$2.89
- OR -

Overview

Setting Up

First let’s setup an ASP.NET application for our tutorial; we’ll call this project MyNav. Begin by adding a new virtual directory in IIS admin called MyNav. Next create a new Visual Basic ASP.NET Web Application in VS.NET with the correct virtual path. Ex: http://localhost/MyNav

Next we need to add a couple of pages for our website which will contain our navigation menu. Right click the project and select Add->Add Web Form… and create 2 new web forms named Home.aspx, and Contact.aspx. On each page add some simple text to identify the page, such as “This is the Home.aspx page” and “This is the Contact.aspx page”.

Before we add our Web User Control we need to customize some stylesheet properties so our navigation menu has some style and color. By default your new MyNav ASP.NET project has a file called Styles.css. Double click this file to open it and replace its contents with the code below:

.nav_buttons

{

      border-right: lightskyblue solid;

      border-top: lightskyblue solid;

      font-weight: bold;

      border-left: lightskyblue solid;

      color: white;

      border-bottom: lightskyblue solid;

      font-family: verdana;

      background-color: #000099;

}

Kevin Koch

Kevin KochKevin Koch is a senior software engineer with over 8 years experience designing and architecting primarily web based applications. Fresh out of college during the nineties he co-founded Task Solutions and developed several projects with the then popular classic ASP.

During the Dot Com boom Kevin left his position as president and joined a new venture to build an enterprise insurance claim system build upon J2EE technology. After the Dot Com crash Kevin schooled himself to become an expert with .NET technology and is currently freelancing his ASP.NET skills to build enterprise n-tier frameworks using advanced OO methodologies.

See All Postings From Kevin Koch >>

Reviews

Be the first to write a review

You must me logged in to write a review.