[NET]MasterPage嵌套及MasterPage中的控件和变量的访问
来源:互联网 发布:vanelife软件 编辑:程序博客网 时间:2024/05/20 16:32
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控件的用法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版
- asp.net 2.0下嵌套masterpage页的可视化编辑
- asp.net 2.0下嵌套masterpage页的可视化编辑
- asp.net 2.0下嵌套masterpage页的可视化编辑
- asp.net 2.0下嵌套masterpage页的可视化编辑
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- 关于子页面调用Masterpage页面变量和控件的方法和实践
- MasterPage
- 在VB和DLL间传递字符串
- 如何让局域网内的一台机器作web服务器
- 整合Spring与Struts的几种方法
- Frame 内置网页的简单方法
- 对学习J2EE有感
- [NET]MasterPage嵌套及MasterPage中的控件和变量的访问
- 毕业进入社会的我们终于变了
- 怎么清除IE浏览器中表单的自动提示?
- 隐藏在XP中的一个秘密武器,完全清除垃圾文件
- PHP应用分页显示制作详细讲解
- 大学,最后我能带走什么?
- Java EE 5 SDK Update 2 下载地址
- 程序员四大忌
- 一个简单的操作活动目录的类(ADHelper)