What is a master page ?

1) A master page provides a framework in which the content of each page on a web site is presented. Master pages make it easy to create pages that have a consistent look.

2) The pages that provide the content that’s displayed in a master page are called content pages .

3) The content of each content page is displayed in the master page’s content placeholder.

Can we add more than one master page to our web application?

Yes We can add more than one master page to our web application

What is a nested master page? How do you create them?

A nested master page is a master page associated with another master page. To create a nested master page, set the MasterPageFile attribute of the @Master directive to the name of the .master file of the base master page.

What is Master Page in ASP.NET?

A Master page offers a template for one or more web forms. It defines placeholders for the content, which can be overridden by the content pages. The content pages contains only content. When users request the content page, ASP.NET merges the layout of the master page with the content of the content page and produce output.

In which way you identify a Master Page and how can you bind a Content Page to a Master Page? Can a master page be nested?

  1. The master page is identified by @Master directive and that replaces the @Page directive which is used for ordinary .aspx or content page pages.
  2. The MasterPageFile attribute of a content page’s @Page directive is used to bind a Content Page to a Master Page.
  3. Yes, the master pages can be nested.

Is it possible to apply theme to a Master page?

If we add the theme attribute to the @ Master directive, the page will raise an error when it runs.

But we can apply themes by using the following approaches:-

  1. As master pages is placeholder/templated and it is merged with the content page very early in the page execution life-cycle. The theme that is applied to the the content pageis applied to the master page as well.
  2. If the site as a whole is configured to use a theme by including a theme definition in the pages element.

Hence there is no theme attribute in the @Master directive.

How can you assign a Master Page dynamically?

You can assign the master page dynamically with the help of Page class property called MasterPageFile . You can assign this when the page is in PreInit stage. Below is the sample code to assign master page dynamically.

void Page_PreInit(Object sender, EventArgs e)

{

this.MasterPageFile = "~/MasterPage.master";

}