Multiple Levels of Master Pages

   This feature provides a way to display standard content from several levels of hierarchy. For
example, a Content page named Publication.aspxcan establish its Master as Research.master,
which can in turn declare its Master as Corporate.master. The final rendering will be of Research
.aspxsurrounded by Research.master, and all of that surrounded by Corporate.master. One prob-
lem is that the space remaining for content is reduced at each level. VWD does not contain automatic
tools to create multiple levels of Masters. In fact, if you have multiple levels, you can only open those
pages in Source View.
 

    To create pages with multiple levels of Masters you must include in the middle-level page tags that both
indicate its Master page (up a level) and its content placeholders (for the lower level). Recall that a
Master page must have <%@Master...%>on the first line, and that a lower-level or Content page must
have <%@PageMasterPageFile=%>on its first line. In the case of a middle page that is both a Content
and Master page, the tag must start with <%@Master...and also contain ...MasterPageFile=%>.
Also recall that a Master page contains an <asp:ContentPlaceHolder>tag whereas the Content page
has an <asp:content>tag. In the case of a middle layer, there must be an <asp:content>holding the
ID of the Master’s <ContentPlaceHolder>tag. Then within that tag there is an <asp:
ContentPlaceHolder>tag that will be used by the next level down.
The following example illustrates a Corporate Master page, then a Research department Master page,
and finally a Publication.aspxpage that holds the content. The Corporate page is shown in the fol-
lowing code. Note that its content placeholder is defined in the shaded lines:

<% @ Master Language = ”C#”  %>
<! DOCTYPE html PUBLIC “ - // W3C // DTD XHTML 1.1 // EN”
“http: // www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
< html xmlns = ”http: // www.w3.org/1999/xhtml” >
< head runat = ”server” >
< title > CorporateMaster </ title >
</ head >
< body >
Corporation Name
< form id = ”form1” runat = ”server” >
< div >
< asp:contentplaceholder 
id
= ”ContentPlaceHolderCorporate” 
runat
= ”server” >
</ asp:contentplaceholder >
</ div >
</ form >
</ body >
</ html >

   The Research department Master page is illustrated by the following code. This page is the most com-
plex, because it is a Content page for the Corporate page, and a Master page for the Publication page.
Notice the use of Masterand MasterPageFile=on the first line that establishes this as content for the
Corporate Master page. Then observe that the <asp:ContentPlaceHolder>will house other pages as
content (in this case the Publication page). The content placeholder must sit wholly within the

< asp:content > tags:
<% @ Master MasterPageFile = ~/ Corporate.master”  Language = ”C#”  %>
< asp:Content runat = ”server” 
ContentPlaceHolderID
= ”ContentPlaceHolderCorporate” >
Research Department
< asp:contentplaceholder 
id
= ”ContentPlaceHolderResearch” 
runat
= ”server” >
</ asp:contentplaceholder >
</ asp:Content >

    Code for the Publication.aspxpage (designed with content only) is shown in the following code.
Here you only need to designate a Master page. This page, which sits at the lowest level, is not a Master
page:

<% @ Page Language = ”C#” MasterPageFile = ~/ Research.master” Title = ”Untitled Page”  %>
< asp:Content ID = ”Content1” 
ContentPlaceHolderID
= ”ContentPlaceHolderResearch” 
Runat
= ”Server” >
Publication text 
</ asp:Content >


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值