Next


Master Pages

• Similar to “User Controls”, the designing can be shared among multiple web pages using “Master Pages” concept.
• A master page is similar to web page, but it’s not a web page.
• The master page file extension is “.master”.
• It also contains some design and code in the “.cs” file.
• It can be executed on the browser directly.
• This is meant for re-usability only.
• That means the master page content can be re-usable by other web pages (.aspx pages).

Implementation of Master Pages

1. Add the Master Page to the Web Site:
• Click on “Web Site” menu – “Add New Item”.
• Select “Master Page”.
• Enter the name of the master page and click on “Add”. Ex: MasterPage.master
2. Design and Develop the Master Page:
• Design the required content in the master page before “ContentPlaceHolder” tag, and write the necessary code in the “.master.cs” file.
• The “ContentPlaceHolder” tag represents the content in the other web pages. In the master page, it should be empty.
3. Create a Web Page with the Reference of Master Page:
• Click on “Web Site” menu – “Add New Item”.
• Select “Web Form”. Enter the name of the new web page.
• Select the option “Select Master Page”.
• Click on “Add”.
• Then it displays the list of all available master pages in the project. Select the master page name and click on “OK”.
• In this content page, you design any content in the “Content” tag.

Demo on Master Pages