32.5. Master Pages

A very useful feature of web development in Visual Studio is the ability to create master pages that define sections that can be customized. This enables you to define a single page design that contains the common elements that should be shared across your entire site, specify areas that can house individualized content, and inherit it for each of the pages on the site.

To add a master page to your Web Application project, use the Add New Item command from the web site menu or from the context menu in the Solution Explorer. This displays the Add New Item dialog, shown in Figure 32-34, which contains a large number of item templates that can be added to a web application. You'll notice that besides Web Forms (.aspx) pages and Web User Controls, you can also add plain HTML files, style sheets, and other web-related file types. To add a master page, select the Master Page template, choose a name for the file, and click "Add."

Figure 32.34. Figure 32-34

When a master page is added to your web site, it starts out as a minimal web page template with two empty ContentPlaceHolder components — one in the body of the web page and one in the head. This is where the detail information can be placed for each individual page. You can create the master page as you would any other web form page, complete with ASP.NET and HTML elements, CSS style sheets, and theming.

If your ...

Get Professional Visual Studio® 2008 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.