Master Pages
 
Working of Master Pages
 
Adding Master page
 
To use master page, create a new web site. Once the new site opens, right –click the project and choose Add New Item. In the dialog box that opens, choose Master Page and name you master page. The new master page has been created with an
 
<asp:contentplaceholder> control declaration already in place:
</asp:contentplaceholder>
<asp:contentplaceholder id=?ContentPlaceHolder1? runat=?server?>
</asp:contentplaceholder>
 
Using Master page in Content page
 
Now create a new .aspx page (web form or content page) and in Add New Dialog box, you must select “Select Master Page? check box. You can also create a content page through right click on the master page and select “Add Content Page?. When Add button is clicked, the Select Master Page dialog will open. Choose filename.master file and click OK. Then web is content page. The master page is visible in non-editable mode with grey shade while working on content page.
 
Dealing with page title
 
By default all the content page automatically uses the title that is declared in the master page.You can avoid this by specifying the page’s title using the Title attribute in the @page directive in the content page.
 
<%@ page Language=?C#? MasterPageFile="~/myMaster.master" %>
<script runat="server">
protected void Page_LoadComplete(Object sender , EventArgs e)
{
Master.Page.Title = “This is page title.?
}
</script>
 
Combination of page types and Languages
 
You can use the Master Page created earlier, either it was created using the inline-coding model or code-behind model. You can combine the coding models as well as programming languages when using master pages or content pages. You can use C# for master page and Visual Basic for content page.
 
Specifying a Master page
 
The final difference between a Master Page and a normal ASP.NET page is that a Master Page can contain zero or more ContentPlaceHolder controls. A ContentPlaceHolder control can be used only within a Master Page. This control marks an area of a Master Page that can be overridden by a particular content page.
 
Sample Code:
 
At Page Level:
 
<%@ page Language=?C#? MasterPageFile="~/myMaster.master" %>
 
At Configuration Level:
 
<configuration>
<location path=?Myfolder?>
<system.web>
< pages masterpagefie=?~/mymaterfile.master? />
</system.web>
</location>
</configuration>