21.9. Adding Breadcrumbs

Problem

You want to use a dynamic menu in your application and display a breadcrumb trail to show the current location within the application and to provide an easy way for the user to navigate back to a previous location.

Solution

Implement the dynamic menu solution described in Recipe 21.8 and add a SiteMapPath control to the .master file. Use the .master file as the master page for all pages in your application that require the dynamic menu and the breadcrumb trail.

Example 21-24 shows the .master file used to display the dynamic menu and breadcrumb trail. Figure 21-9 shows the output a sample page with the breadcrumb trail displayed.

Sample page with dynamic menu and breadcrumb trail

Figure 21-9. Sample page with dynamic menu and breadcrumb trail

Discussion

To improve the user experience, applications commonly display a breadcrumb trail to show the current location within the application and to provide an easy way to navigate back to a previous location. The site navigation infrastructure provided in ASP.NET 2.0 can be used to display a breadcrumb trail using the data in the Web.sitemap file that is also used to as the data source for dynamic menus (see Recipe 21.8).

Once you have the site structure defined in the Web.sitemap file, as described in Recipe 21.8, all that is required is to add a SiteMapPath control to the .master file that will be used as the master page for your application pages that need to ...

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.