21.8. Dynamic Menus
Problem
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.
Solution
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:
Add a
siteMapNode
element for each section of your application.Add a
siteMapNode
element for each page in the sections.
In the .master file:
Add a
SiteMapDataSource
control.Add a
Menu
control.Set the
DataSourceID
attribute of theMenu
control to the value of theID
attribute of theSiteMapDataSource
control.
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 ...
Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.