您的位置:首页 > 编程语言 > ASP

红皮书_ASP.NET2.0网站开发全程解析_第2章_母版

2010-03-18 10:49 281 查看
让我们重头嚼起

使用母版页:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Master_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>母板页</title>
</head>
<body>
<form id="form1" runat="server">

<!-- 母板页头 star -->
<div id="header" style="border:2px solid blue;margin-top:10px;padding:10px" mce_style="border:2px solid blue;margin-top:10px;padding:10px">
母板页头<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<!-- 母板页头 end -->

<!-- 母板页主体内容 star -->
<div>
<asp:contentplaceholder id="MasterPageContent" runat="server">
</asp:contentplaceholder>
</div>
<!-- 母板页主体内容 end -->

<!-- 母板页脚 star -->
<div id="footer" style="border:2px solid blue;margin-top:10px;padding:10px" mce_style="border:2px solid blue;margin-top:10px;padding:10px">
母板页脚
</div>
<!-- 母板页脚 end -->

</form>
</body>
</html>


子页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Master_Default" MasterPageFile="~/Master/MasterPage.master" Title="使用通用母板页的内容页面1" %>
<%@ MasterType VirtualPath="~/Master/MasterPage.master" %>
<%-- 使用强类型方便访问母板 --%>


子页面后台:

this.Master.TextBoxVisible = false; //访问母版页中定义的属性值

TextBox tb = (TextBox)this.Master.FindControl("TextBox1"); //访问母版页中控件

后续补充:

可在母版页的<head></head>标签中插入内容,以便为各子页自由包含引入文件

母版:

<head runat="server">

<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>

</head>


子页:

asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<!-- 包含当前页显示样式 star -->
<link href="../../css/ChineseClub.css" mce_href="css/ChineseClub.css" rel="Stylesheet" type="text/css" />
<!-- 包含当前页显示样式 end -->
</asp:Content>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: