Published on: 10 July, 2013

ASP.Net Master Page

Posted by andy | 2448 views 0 likes 0 favourites 0 comments
Tumblr Digg Google Plus

Master Page can be defined as a template that can be re-used as a foundation for your site page. Let's say, you have a design of a site template contains the same header and footer and the only different is actually the main body content. Rather than making all page contains the header and footer content, we can create a template master page file to handle this situation. Let's say we have the following template as an example. Both header and footer will always stay the same while the only content that will be dynamic is the content part (middle content). master page

So what are the advantage to use Master Page?

The advantage of using Master Page is quite obvious. The advantage are better files management and layout structure. Rather than seeing the whole content layout of header, body content and footer, you can just only need to take care and focus on body content. Therefore, your code will be easy to read and manage. If put a phone number or links on your footer or header content, you just need to modify these content in master page. Imagine, if you don't use master page feature, you will have to open all page files and update the details one by one.

How to create Master Page?

To create master page is pretty simply, click add a new item on your website project and you will see the following option.

create master page

Once the master page has been created, you will see the file has an extension of .master, see below sample of default master page. We named our master page example_masterpage.master

//Take a notice of wording Master in the header.
<%@ Master Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <asp:ContentPlaceHolder id="head" runat="server">
	//this is where the content will be located.
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        //this is where the content will be located.

This is how you create a page and link the master page template to the current page. Right click your site project and choose web form and tick a checkbox option at the bottom saying Select Master Page. See below images for more details.

link master page to a page

select master page


There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Related Articles
Published on: 13 February, 2017
One thing to remember when publishing your ASP.Net web applications, you may find out, some files could be not completely published due to the settings on the file properties. One example that I had are some font types file. In order to fix this problem you can navigate to the files that are missing and right click the properties.