in Education by
What is master page in ASP.NET?

1 Answer

0 votes
by

The extension of MasterPage is '.master'. MasterPage cannot be directly accessed from the client because it just acts as a template for the other Content Pages. In a MasterPage we can have content either inside ContentPlaceHolder or outside it. Only content inside the ContentPlaceHolder can be customized in the Content Page. We can have multiple masters in one web application.A MasterPage can have another MasterPage as Master to it. The MasterPageFile property of a webform can be set dynamically and it should be done either in or before the Page_PreInit event of the WebForm. Page.MasterPageFile = "MasterPage.master". The dynamically set Master Page must have the ContentPlaceHolder whose content has been customized in the WebForm.

A master page is defined using the following code,

<%@ master language="C#" %>

Adding a MasterPage to the Project 

  1. Add a new MasterPage file (MainMaster.master) to the Web Application.
  2. Change the Id of ContentPlaceHolder in <Head> to "cphHead" and the Id "ContentPlaceHolder1" to "cphFirst".
  3. Add one more ContentPlaceHolder (cphSecond) to Master page.
  4. To the master page add some header, footer and some default content for both the content place holders.
    1. <form id="form1" runat="server"> Header...  
    2.     <br />  
    3.     <asp:ContentPlaceHolder id="cphFirst" runat="server"> This is First Content Place Holder (Default) </asp: ContentPlaceHolder>  
    4.         <br />  
    5.         <asp:ContentPlaceHolder ID="cphSecond" runat="server">  

This is the second Content Place Holder (Default).

  1. </asp:ContentPlaceHolder>  
  2.    <br /> Footer...  
  3. </form>  

Related questions

0 votes
    How can we improve the Performance of an ASP.NET Web Page?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is cross-page posting in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the ASP.NET page life cycle events?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is the ASP.NET page life Cycle?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is Enterprise Library in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is Data Cache in ASP.NET and how to use?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    What are the Navigations techniques in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is Themes in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    Explain Cookie-less Session in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is the PostBack property in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    What are the differences between ASP.NET HttpHandler and HttpModule?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is the difference between HttpContext.Current.Items and HttpContext.Current.Session in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
...