1. Back To Blog

ASP.NET Interview question :- Can you explain master pages concept in ASP.NET ( Training )?

Master pages are templates which can be applied to your web pages to bring in consistent look and feel and uniform structure. By creating templates we also avoid lot of duplication of code across web pages.

For example let's say you want all your web pages in your application to have left menu, banner and footer (Refer figure Master page concept). So you can create a template and then apply that template to your webpages.

So how do you create master pages?

To create a master page you can use the "master page" template from visual studio as shown in the below figure. In order to apply the master template we can use "Web form using master page" template.

In the master page you can define place holder using "ContentPlaceHolder" control. This is the place where your ASP.NET pages will be plug in their data.


    This is the common template

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">



Once the master page template is created with the necessary place holders. You can then later in the web pages use the "MasterPageFile" to refer the template and you can use the content place holder to plug data.

For instance you can see the below code snippet of a page which uses master pages. You can also see how the "ContentPlaceHolder1" is used to place a simple text data "Company was established in 1990".

<%@ Page Title="" Language="C#" MasterPageFile="/WebSiteTemplate.Master" AutoEventWireup="true" CodeBehind="Aboutus.aspx.cs" Inherits="MasterPageDemo.Aboutus" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">


        Company was established in 1990</p>


Also see  the following video on ASP.NET Master pages

See for more stuffs on ASP.NET Interview question


Click to view more from author's on ASP.NET Interview question

You can also buy  Dotnet interview questions and answers  book by clicking here

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social