04 ASP - Net Session05
04 ASP - Net Session05
NET
Objectives
Master pages:
Are ASP.NET files similar to ASP.NET Web Forms.
Define consistent, reusable layouts, code, and content that is
typically used by more than one Web page in a Web
application.
Have a file extension of .master.
Contain the @Master directive.
Do not represent complete Web pages. The content and
functionality is incorporated with other Web pages on the same
Web site at run time.
Content Pages:
Reference a master page for consistent layout, reusable code,
reusable content, and controls.
Enable you to create specific content that is included at run
time with the generic content from a master page.
Reference a master page by including a MasterPageFile
attribute in the @Page directive.
Contain page-specific content in Content controls. These
Content controls are merged at run time with corresponding
ContentPlaceholder controls on the referenced master
page.
Page-Specific Content
Parent.master file:
<%@ Master Language="C#" %>
<HTML>
<BODY>
----------Some Tags---------
<asp:ContentPlaceHolder ID="MainContent"
runat="server“ />
----------Some Tags---------
</BODY>
</HTML>
Child.master file:
<%@ Master Language="C#“
MasterPageFile="Parent.master"%>
<asp:Content id="Content1“
ContentPlaceholderID="MainContent"
runat="server">
--------------Some Tags--------
<asp:ContentPlaceHolder ID= "ChildContent"
runat="server" />
--------------Some Tags----------
<asp:ContentPlaceHolder ID="ChildFooter“
runat="server" />
-----------Some Tags------------
</asp:Content>
Child.aspx file:
<%@ Page Language="C#“
MasterPageFile="Child.Master"%>
<asp:Content id="pageContent"
ContentPlaceholderID="ChildContent"
runat="server">
----------Some Tags---------
</asp:Content>
<asp:Content id="footerContent"
ContentPlaceholderID="ChildFooter"
runat=server>
----------Some Tags---------
</asp:Content>
Problem Statement:
You are a developer in the Adventure Works organization, a
fictitious bicycle manufacturer. You have been asked to assist
in the development of the Business-to-Consumer (B2C) Web
application and a related Business-to-Employee (B2E) extranet
portal.
Decisions on the design of the application have already been
made. You have been asked to carry out a number of specific
tasks in order to implement various elements of this design. As
part of the first phase of the B2C development, you have been
asked to implement a hierarchy of master pages that enable
commonly used user interface elements to be defined in one
place and then reused in many Web pages throughout the site.
Solution:
You need to perform following tasks:
1. Design a Master Page
a. Open the Adventure Works Web site.
b. Create the TopLevel.master page.
c. Define the layout of the TopLevel.master page.
d. Write code for the TopLevel.master page.