Asp.Net Master模板页的控件和属性
内容页访问MasterPage中的控件,有两种解决方案:
一、是用弱类型访问
使用 FindControl 方法获取模板页的控件
((Label)Master.FindControl("Label1")).Text = "xxx";
二、给模板页添加属性来使用强类型访问(推荐)
模板页定义;
//属性
private string x;
public string X
{
get { return this.x; }
set { this.x = value; }
}
//控件的属性以属性的形式公开给内容页
public string LabelCaption
{
get { return this.Label1.Text; }
set { this.Label1.Text = value; }
}
模板页使用属性的时候,内容页要访问的话,必须在模板页中加入一条指令,如:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
//使用Master关键字获取模板页的信息
Master.TextBoxValue = "xxx";
Master.LabelCaption= "yyy";
Master.X = "zzz";
如果不是用<%@ MasterType VirtualPath="~/MasterPage.master" %>将会编译错误,也不会出想智能提示
相关文档:
1.Application:用于保存所有用户共用的数据信息。 在Asp.Net中类似的配置数据最好保存在Web.config文件中。如果使用Application对象,一个需要考虑的问题是任何写操作都要在 Application_OnStart事件(global.asax)中完成。尽管使用Application.Lock和 Application.Unlock方法来避免写操作的同步,但是它串行化了Applicat ......
if(MyFile.PostedFile.ContentType != "image/gif"
&& MyFile.PostedFile.ContentType != "image/jpg"
&& MyFile.PostedFile.ContentType != "image/pjpeg"
&& &n ......
http://ayic1.blog.163.com/blog/static/27343030200965103528805/
静态变量
当我们编写一个类时,其实就是在描述其对象的属性和行为,而并没有产生实质上的对象,只有通过new关键字才会产生出对象,这时系统才会分配内存空间给对象,其方法才可以供外部调用。
& ......
ASP.NET 生命周期
对于Asp.net页面层开发无论是写页面还是写控件,我觉得都可以用一句话描述:"Do the right thing at the right time in the right place."
本文通过记录页面事件的触发顺序看请求的处理流程,从中可以看出ASP.NET 的生命周期
创建一个网站,在页面上添加一个Label和一个Button,在Default.aspx.cs中修改 ......