What Is Master Page?: Content Pages
What Is Master Page?: Content Pages
ASP.NET master pages allow you to create a consistent layout for the pages in your
application. A single master page defines the look and feel and standard behavior that
you want for all of the pages (or a group of pages) in your application. You can then create
individual content pages that contain the content you want to display. When users request
the content pages, they merge with the master page to produce output that combines the
layout of the master page with the content from the content page.
Content Pages
You define the content for the master page's placeholder controls by creating individual
content pages, which are ASP.NET pages (.aspx files and, optionally, code-behind files)
that are bound to a specific master page. The binding is established in the content
page's @ Page directive by including a MasterPageFile attribute that points to the
master page to be used. For example, a content page might have the
following @ Page directive, which binds it to the Master1.master page.
<%@ Page Language="C#" MasterPageFile="~/MasterPages/Master1.master"
Title="Content Page"%>
In the content page, you create the content by adding Content controls and mapping them
to ContentPlaceHolder controls on the master page.
For example, the master page might have content placeholders called Main and Footer.
In the content page, you can create two Content controls, one that is mapped to
the ContentPlaceHolder control Main and the other mapped to
the ContentPlaceHolder control Footer, as shown in the following figure.
Replacing placeholder content
A content page might look like the following.
<% @ Page Language="C#" MasterPageFile="~/Master.master"
Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main"
Runat="Server">
Main content.
</asp:Content>