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
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:
border-right: lightskyblue solid;
border-top: lightskyblue solid;
border-left: lightskyblue solid;
border-bottom: lightskyblue solid;