You want to create a navigation bar that lets you add or remove items without changing code so you can reuse the navigation bar in multiple applications.
Create an XML document containing the items that will be displayed in the navigation bar, and then create a user control that uses the contents of the XML document to provide the required customization.
To create the user control:
Create a file with a .ascx extension.
@ Control directive at the top of the file.
DataList control configured to render a table with an
ItemTemplate defining the cells in the table.
In the code-behind class for the control, use the .NET language of your choice to:
Create a user control code-behind class that inherits from the
(Optional) Establish properties for the control that will provide the ability to control programmatically the basic look of the navigation bar, such as its background color.
To use the user control in an ASP.NET page:
Register the control by using the
@ Register directive at the top of the page.
Place the tag for the user control in the HTML where you want the control rendered.
The output of a test page demonstrating a typical navigation bar user control is shown in Figure 5-2. Example 5-7 shows the XML document we created to define the contents of the navigation bar. Example 5-8 shows the .ascx file for the user control. Examples 5-9 and 5-10 show the VB and C# code-behind files for the user control. ...