您的位置:首页 > 其它

母版页可以多层嵌套使用

2006-08-18 08:51 393 查看
①首先是“父”母版页,与一般的母版页差不多,除了一些固定的内容,页面中间留下大片的“空白”区域:

<!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>MasterPage可以多层嵌套使用</title>
</head>
<body>
<form id="form1" runat="server">
<table border="1" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td colspan="2" align="center" style="background-color: mediumturquoise" >MasterPage可以多层嵌套使用~~~</td>
</tr>
<tr>
<td valign="top" width="150" class="nav" style="background-color: lightcyan">
<table border="0" width="100%" cellpadding="4" cellspacing="0">
<tr>
<td><a href="#">超链接一</a></td>
</tr>
<tr>
<td><a href="#">超链接二</a></td>
</tr>
<tr>
<td><a href="#">超链接三</a></td>
</tr>
<tr>
<td><a href="#">超链接四</a></td>
</tr>
<tr>
<td><a href="#">…………</a></td>
</tr>
<tr>
<td style="font-size: x-small; color: forestgreen; ">(上面这些链接都是假的,点了也没什么效果)</td>
</tr>
</table>
</td>
<td valign="top" align="center">
<asp:contentplaceholder id="ChildMaster" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" align="center" style="background-color: lightyellow" ><a href="#" onclick="window.close();">GoodBye</a></td>
</tr>
</table>
</form>
</body>
</html>

②然后是“子”母版页,它填充了上面的母板页所留下的空白,同时,再次留下3块“空白”的区域:

<asp:content id="ChildMaster" contentplaceholderid="ChildMaster" runat="Server">
<table border="1" cellpadding="10" cellspacing="0" width="100%" height="100%">
<tr>
<td align="left" colspan="2" style="font-style: italic;">“子”母版页:
</td>
</tr>
<tr>
<td align="left" colspan="2" >
<asp:contentplaceholder id="ContentTitle" runat="Server" />
</td>
</tr>
<tr>
<td align="left" valign="top" >
<asp:contentplaceholder id="ContentText" runat="Server" />
</td>
<td align="left" width="150" valign="top" >
<asp:contentplaceholder id="ContentNav" runat="Server" />
</td>
</tr>
</table>
</asp:content>

稍稍遗憾的是,上面的HTML只能手写,因为不但我们在添加一个新母版页时无法勾选“选择母版页”,并且还无法切换到设计视图:

<asp:content id="ContentTitle" contentplaceholderid="ContentTitle" runat="Server">
<h1>区域A:Content Title</h1>
</asp:content>

<asp:content id="ContentText" contentplaceholderid="ContentText" runat="Server">
<p>区域B</p>
</asp:content>

<asp:content id="ContentNav" contentplaceholderid="ContentNav" runat="Server">
<p>区域C</p>
</asp:content>

同样遗憾的是,设计上面的页面时也无法切换到设计视图。

在页面中的各个区域里设计好适当的内容后,运行起来,可以得到下面的效果:



这时候我们也许会有一个疑问:为什么要用多层嵌套的母版页?象上面的例子,一开始就在页面上
留下3块区域不是更方便吗?
大概应该这样考虑:站点可能使用一个统一的母版页所为主框架,然后在一片较大的区域中,某一些情况需要分成3块的样式,某一些则会是4块,也许还会有更复杂的要求,这时候多层嵌套就有用了。
但是问题又来了:设计起来这么不方便,该如何使用呢?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: