Master Page:: Source: Mindcracker Network
Master Page:: Source: Mindcracker Network
Master Page:: Source: Mindcracker Network
com)
Master page:
Master page enable you to share the same content among multiple content pages in a
website. We can use master page to create a common page layout.
For Example: If you want all the pages in your website to share a three column layout,
you can create the layout once in a master page and apply the layout to multiple content
pages.
You can make your website easier to maintain, extend and modify by using master page.
If you want to display a standard header and footer in each page in your website, then
we can create the standard header and footer in a master page.
If you want to add a new page in your website that looks just like the other pages in
your website, then we simply need to apply the same master page to the new content
page.
You can completely modify the design of your website without change every content
page. You can modify just a single master page to dramatically change the appearance of
all the pages in your application.
A Master Page can contain the same Web controls, User controls, HTML content, and
scripts that can be added to a standard ASP.NET page.
If you have an existing web site, you can skip this section. Otherwise, you can create a
new web site and page by following these steps.
In the Language list, click Visual Basic (or the language you prefer to work with).
Click OK.
Visual Web Developer creates the folder and a new page named Default.aspx.
You create a master page visual web developer by selecting the website menu option,
add new item in server explore and selecting the master page option from the add new
item page.
Figure: This figure represent how to select the master page
The source file of master page is as follows:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
You create a master page by creating a file that ends with the .master extension.
In the application you can locate a master page file any place. You can add multiple
master pages to the same application.
You can place almost all the same elements in a master page that you could place in
asp.net page, including HTML, server side scripts and ASP.NET controls.
There are two special things about the master page,
Second notice that the master page includes two <contentplaceholder>. You can
add as many <contentplaceholder> to a master page as you need.
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
For Example: Now we are creating a master page. The source file of that master page's
is as follows:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>My master page</title>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<div class="left column">
<asp:contentplaceholder id="contentplaceholder1" runat="server">
<B/><I>IMPORTANT WEBSITE FOR LEARNING
DOTNET TECHNOLOGY</I><BR/><BR>
asp.netheaven.com<br/>
dotnetheaven.com<br/>
c-sharpcorner.com<br/>
vb.netheaven.com<br/>
</asp:contentplaceholder>
</div>
<div class="right column">
<asp:contentplaceholder ID="contentplaceholder2" runat="server">
<B/><I>OUR NETWORK</I><BR/><BR/>
longhorncorner.com<br/>
interviewcorner.com<br/>
mindcracker.com<br/>
microgold.com<br/>
</asp:contentplaceholder>
</div><br class="clear"/></div>
</form>
</body>
</html>
Output:
This page will open after debugging these codes.
Figure: My master page.
There are two contentplaceholder in the above page. We can add multiple
contentplaceholder in the master page.
You can't cache a master page with the output cache directive. You also can't apply a
theme to a master page.
Master page uses cascading style sheets (CSS) to create the page layout. HTML tables
should be used only to display tabular information.
Run-time Behavior of Master Pages:
At run time, master pages are handled in the following sequence:
The master page with the updated content is merged into the control tree of the
content page.
Conclusions:
Master pages provide a key component to any web application, namely the ability to
organize a consistent layout into reusable templates. These master page templates offer
full designer support and programmatic interfaces to meet the demands of most
applications.
Thank you for using Mindcracker Network