In ASP.NET 2.0, Microsoft introduced the concept of Master
Pages. Master Pages are a common base file that provides consistent layout
across multiple pages in your application. You can have a single Master Page or
multiple Master Pages in your application. To use Master Pages in your
application, you create a Master Page with the extension .master. This Master
Page will hold the site layout and design. The next step will be to create
multiple content pages based on the Master Page. On the Master Page you need to
define the content server control. The definition of the content server control
looks like the following.
Listing 1
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="server">
This content place holder will hold the controls that are
specific to the content pages. You can have single or multiple content place
holders.
When you create new Content Pages, you can either specify
the MasterPageFile attribute on the page or you can specify it in the Web.Config
file. In Content Pages your attribute will look like:
Listing 2
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb"
Inherits="ReportsApp._Default" MasterPageFile="~/ReportingApp.Master"%>
In Web.Config file it will look be:
Listing 3
<configuration>
<pages masterpagefile="~/ ReportingApp.master">
</configuration>
If we just have one Content Place holder then the page will
be designed as follows.
Listing 4
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb"
Inherits="ReportsApp._Default" MasterPageFile="~/ReportingApp.Master"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>
If you would like to dynamically assign the Master Page file
then it has to be done in the Page_PreInit event.
Listing 5
MasterPageFile ="~/ReportingApp.Master"
Any item that is specific to this page goes inside the Content Place holder. You can have multiple Content Place holder controls on your page with
different ID's. If you need more information on Master Pages you can review
various articles by searching on Master Pages in Google.com.