Chapter 10. Master Pages and Navigation

Web sites look better and are less confusing to users when they have a consistent "look and feel" as you move from page to page. ASP.NET 2.0 facilitates creating consistency with master pages .

A master page provides shared HTML, controls, and code that can be used as a template for all of the pages of a site. The O'Reilly web site (http://www.oreilly.com) is a good example of a site that could be implemented using a master page. With a master page, the logo (the O'Reilly tarsier) and an image (the O'Reilly header) can be shared across multiple pages.

Creating Master Pages

To get started with master pages, you'll take the following steps:

  1. Create a new web site.

  2. Add a master page to the site.

  3. Add content pages based on the master page.

To begin, create a new web site and call it MasterPages. Once the new site opens, right-click on the project and choose Add New Item. In the dialog box that opens, choose Master Page, and name your master page SiteMasterPage.master, as shown Figure 10-1.

An asp:contentplaceholder control has been added for you in the new page. It is this placeholder that will be filled by the content of each of the pages that use this master page.

Within the master page itself you may add anything you like surrounding the contentplaceholder. Whatever you add will be displayed on all pages that use the master page.

Add new master page

Figure 10-1. Add ...

Get Programming Visual Basic 2005 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.