母板页的嵌套使用
2006-09-21 22:11
309 查看
出自:http://www.cnblogs.com/eddie005/services/trackbacks/442882.aspx
①首先是“父”母版页,与一般的母版页差不多,除了一些固定的内容,页面中间留下大片的“空白”区域:
<!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块,也许还会有更复杂的要求,这时候多层嵌套就有用了。
但是问题又来了:设计起来这么不方便,该如何使用呢?
①首先是“父”母版页,与一般的母版页差不多,除了一些固定的内容,页面中间留下大片的“空白”区域:
<!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块,也许还会有更复杂的要求,这时候多层嵌套就有用了。
但是问题又来了:设计起来这么不方便,该如何使用呢?
相关文章推荐
- asp.net中母板页如何嵌套使用
- STL中map的嵌套使用
- 在 Linux 下使用 RAID(六):设置 RAID 10 或 1 + 0(嵌套)
- Flex服务器端SQL(Ibatis)中使用嵌套List的方法
- 学会如何使用LESS(二)----嵌套规则、运算、命名空间和作用域
- 数组字典的嵌套使用
- 使用正则表达式匹配嵌套Html标签
- HOW TO:使用嵌套 Repeater 控件和 Visual Basic .NET显示分层数据
- Unity 协程使用(嵌套)
- ListView中能嵌套使用'GridView'吗?
- 结构体 嵌套使用
- 使用正则表达式匹配嵌套Html标签
- SQl CASE 语句的嵌套使用方式
- shell中嵌套使用expect 实例
- Android Fragment嵌套使用存在的一些BUG以及解决方法
- protobuf 中的嵌套消息的使用
- ScrollView和GridView嵌套使用出现的冲突问题
- ListView嵌套GridView使用详解及注意事项
- ViewPager嵌套fragment简单使用
- protobuf 嵌套消息的使用