MasterPage嵌套及MasterPage中的控件和变量的访问
来源:互联网 发布:制造业大数据分析 编辑:程序博客网 时间:2024/05/20 19:15
MasterPage嵌套及MasterPage中的控件和变量的访问
1. 嵌套母版页(1) 主母版页 MainMasterPage.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MainMasterPage.master.cs"
Inherits="MainMasterPage" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body leftmargin="0" topmargin="0">
<form id="form1" runat="server">
<div align="center">
<table width="763" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="763" valign="top">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
</form>
</body>
</html> (2)子母版页 (这种只能手动创建这文件)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SubMasterPage.master.cs" MasterPageFile="~/MainMasterPage.master"
Inherits="SubMasterPage" %>
<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="244" valign="bottom">
<img src="images/pagepic.gif" width="244" height="223">
<h1>
以上内容来自子母版页</h1>
</td>
<td valign="top" align="left">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" Runat="server">
</asp:ContentPlaceHolder></td>
</tr>
</table>
</asp:content> (3)内容页
<%@ Page Language="C#" MasterPageFile="~/SubMasterPage.master" AutoEventWireup="true"
CodeFile="Index.aspx.cs" Inherits="Index" Title="示例5-2" %>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder2" runat="server">
<p>
</p>
<p>
</p>
<h1>
网站介绍</h1>
<p>
本页面采用来自ASP.NET 2.0技术的母版页新特性进行开发。 主要包括两个页面:母版页和内容页。 母版页后缀名是.master,其封装网站中的共用元素。 内容页实际是普通的.aspx文件,它包含除母版页的其他内容。
在运行时,ASP.NET引擎将两种页面内容合并执行,最后将结果发给客户端浏览器。</p>
<br>
<h1>
以上内容来自内容页</h1>
</asp:Content>
2. 访问母版页控件和属性
(1) 母版页后台代码访问
在母版页前台页面中添加一个服务器控件
<asp:Label ID="LabelInMaster" runat="server"></asp:Label>
然后在母版页的Page_Load事件中写代码
protected void Page_Load(object sender, EventArgs e)
{
LabelInMaster.Text = "现在时间:" + System.DateTime.Now.ToShortTimeString();
}
(2) 在内容页面中调用母版页控件
在母版添加控件和属性
<asp:Label ID="Label1" runat="server"></asp:Label>
public Label MasterPageLabel
{
get
{
return Label1;
}
set
{
Label1 = value;
}
}
先要在内容页面中添加
<%@ MasterType VirtualPath="~/MasterPage22.master" %>
然后后台才能调用
protected void Page_Load(object sender, EventArgs e)
{
Master.MasterPageLabel.Text = "现在时间:" + System.DateTime.Now.ToShortTimeString();
Master.MasterPageLabel.Font.Size = 20;
}
(3) 同上,内容页面设置变量的值(绑定值)
在母版添加绑定标识、变量和属性
<%= LabelText %>
string _labelText = "";
public String LabelText
{
get
{
return _labelText;
}
set
{
_labelText = value;
}
}
同上在内容页面里加上:
<%@ MasterType VirtualPath="~/MasterPage33.master" %>
在后台代码中
protected void Page_Load(object sender, EventArgs e)
{
Master.LabelText = "现在时间:" + System.DateTime.Now.ToShortTimeString();
}
- MasterPage嵌套及MasterPage中的控件和变量的访问
- [NET]MasterPage嵌套及MasterPage中的控件和变量的访问
- 如何取得和当前页面的MasterPage中的变量?
- 如何取得和当前页面联系的MasterPage中的变量
- MasterPage控件的用法
- 关于子页面调用Masterpage页面变量和控件的方法和实践
- MasterPage
- MasterPage
- 使用masterpage时,js访问服务端控件
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页的方法
- masterpage中FORM和控件ID
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版
- masterpage控件学习
- MasterPage 控件应用
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- 嵌入式开发都需要学习什么
- 转贴:中国又一款开源操作系统酷博linux问世。
- JasperReports给java web报表开发人员带来希望
- 网络资源
- MSDTC 分布式事务错误解决
- MasterPage嵌套及MasterPage中的控件和变量的访问
- CRM
- ADO Connection Strings
- 在线文档:HIBERNATE - 符合Java习惯的关系数据库持久化
- 经验共享:如何做好系统测试!
- Spring集成XFire开发WebService
- delphi 文件操作
- 英特尔去哪儿啦
- 用CSS定义标题的几个实例