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.<%=...%>与<%#... %>的区别:
答:<%=...%>是在程序执行时调用,<%#... %>是在DataBind()方法之后被调用
2.控件接收哪些类型数据?
答:接收Bind的控件,一般有DropDownList,DataList,DataGrid,ListBox这些集合性质 ......
使用URL重写可以实现用http://www.mzwu.com/d100.aspx类似的地址来访问http://www.mzwu.com
/default.aspx?id=100,这样的好处非常多:一是隐藏了真实路径,提高应用程序的安全性;二是有利于搜索引擎收录;三是便于记忆。下边
我们来看看在ASP.NET中怎么实现URL重写。
1.下载URLRewriter.dll
放到Bin文件夹中。
2.Web ......
1.Application:用于保存所有用户共用的数据信息。 在Asp.Net中类似的配置数据最好保存在Web.config文件中。如果使用Application对象,一个需要考虑的问题是任何写操作都要在 Application_OnStart事件(global.asax)中完成。尽管使用Application.Lock和 Application.Unlock方法来避免写操作的同步,但是它串行化了Applicat ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient; ......
来源:草根站长
Cookie (HttpCookie的实例)提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用Cookie 存储用户首选项或其他信息。当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
ASP.NET中的cookie:创建Cookie方法 (1)
Response.Cookies["userName"].Valu ......