Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere

Master Page

Sometimes you come across a situation where you want to have a comman layout across the pages e.g. each page has common header and common footer but has different content. Microsoft has provided Master pages to achieve this functionality.
Master pages allow you to create a consistent look and behavior for all the pages(pages on which you want the common layout) in your web application.
A master page provides a template for other pages to share a common layout and functionality. The master page defines placeholders for the content, which can be overridden by content pages. The output generated is a combination of the master page and the content page. The content pages contains the content which you want to display on your web page.
When browser requests the page, ASP.NET merges the pages to produce output that combines the layout of the master page with the content of the content page.
To add master page in your application-
Goto Solution Explorer-->Right Click-->Choose Add new Item
it will open a dialog box.Choose master page from the templates list, give a name to master page and click on add to add master page to your solution.
A master page file has .master extension.
Adding a Master Page example

Master page code file-
Master Page code example

Below image show to use of master page in content page.
Using a Master Page example

So this is all about master pages.Few terms which are need to be remember in master pages.
ContentPage: The ASP.NET web page that will use master page to have the common UI elements displayed on rendering itself.
ContentPlaceHolder: A control that should be added on the MasterPage which will reserve the area for the content pages to render their contents.