21.8. Dynamic Menus
You want to use a dynamic menu in your application to provide a compact means for a user to navigate within your application, and you want to accomplish this without using a third-party control.
Create a Web.sitemap file to define the pages and navigation in your application. Create a .master file containing a
SiteMapDataSource control and a
Menu control with the
DataSourceID set to the
ID of the
SiteMapDataSource control and other HTML common to all pages in your application. Use the .master file as the master page for all pages in your application that require the dynamic menu.
In the Web.sitemap file:
siteMapNodeelement for each section of your application.
siteMapNodeelement for each page in the sections.
In the .master file:
DataSourceIDattribute of the
Menucontrol to the value of the
IDattribute of the
In the .aspx files that require the dynamic menu, set the
MasterPageFile attribute of the
@ Page directive to the name of the .master file.
Example 21-21 shows the Web.sitemap file, Example 21-22 shows the .master file, and Example 21-23 shows the .aspx file for this example. Figure 21-7 shows the output of the test page with the dynamic menu in the static state. Figure 21-8 shows the output with the dynamic menu expanded.
Figure 21-7. Dynamic menu in ...