Master Page.

Master Pages enables you the developer to create a consistent look and feel for your web application. For most of us, we either create a header and footer on each and every webpage or we create a header and footer control and then add those controls to each and every .aspx page.

A master page is similar to a ‘.aspx’ page except that it has its own unique extension, ‘.master’. Furthermore, a master page contains a new ‘Master’ directive, along with a ContentPlaceHolder control

Master pages give your site a steady look and feel

Master pages contain both HTML and a code part and it create a common template that can be used on many pages

Updating the master page automatically updates all pages using it

A master page has 2 parts

  1. Content that appears on each page that inherits the master page
  2. Regions that can be customized by the pages inheriting the master page

Master pages can contain HTML, Web controls and server side source code

To Add a Master Page in the application follow the steps
1: Right Click Solution Explorer | Select Add New Item. This will give the following dialog box (see Figure 1):

Select Master Page and click Add. Master Page will be added to your website


Master pages end with .Master. By default visual studio names the master page masterPage.master

A Master page need to specify both the parts common to all pages and the parts that are customizable

Items you add to the master page appear on all pages that inherit it

Use contentPlaceHolder controls to specify a region that can be customized

Add a table to the Master page

After creating the master page, notice that it looks like any other page, but it uses a new directive called <%@ Master %>:

<%@ Master Language="C#" 
      ClassName="MasterPage_master" %>

You can also place default content within the ContentPlaceHolder:

   No default content specified


It adds on ContentPlaceHolder by default

If you place controls outside the content placeholders they will be displayed on all pages

2.Right Click the Solution Explorer and select Add New Item and Select Web Form and Check Select Master Page


From the Select a Master Dialog, select the master page and click OK

  • Select the master page you created.

All masterpages in your site will appear


All is grayed out except the contentPlaceHolder control

You can only add controls to and modify inside the ContentPlaceHolder

You can only add controls to and modify inside the ContentPlaceHolder

The purpose of a master page is to define a template for the website

Master pages contain a default contentPlaceHolder control when you create

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: