- 热门文章:
- · (ASP.NET)修改和删除DataGrid行——数据库访问
- · .Net的Outofmemory异常及大内存使用
- · 从 ASP.NET 服务器控件插入客户端脚本(引自MSDN中文网站)
- · ASP.NET应用程序资源访问安全模型
- · 在 ASP.NET 开发中使用非 .Net Web 服务
- · .net 开发人员应必须拥有的10个工具
- · ASP.NET用户控件返回事件的方法
- · 动态生成asp.net控件
- · ASP.NET应用程序的安全方案(二)—授权
- · 如何实现Asp与Asp.Net共享Session
- · ASP.NET应用程序的安全方案(一)
- · 多层结构来开发ASP.NET程序
上一篇:ASP.NET Tips1---合并多个字段值 >>
ASP.NET中使用Server.Transfer()方法在页间传值
下面的示例建立了WebForm1和WebForm2,通过Server.Transfer()方法演示在WebForm2中读取WebForm1的文本框、读取属性、通过Context传值、调用WebForm1的方法等:
WebForm1上放置一个TextBox1和一个Button1,程序如下:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
Context.Items.Add("Context","Context from Form1");
}
public string Time
{
get{return DateTime.Now.ToString();}
}
public string TestFun()
{
return "Function of WebForm1 Called";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("WebForm2.aspx", true);
}
在WebForm2上放置一个Literal1控件,程序如下:
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal Literal1;
private void Page_Load(object sender, System.EventArgs e)
{
string strTxt="";
WebForm1 oForm=(WebForm1)this.Context.Handler;
strTxt+="Value of Textbox:"+Request.Form["TextBox1"] +"<br>";
strTxt+="Time Property:"+oForm.Time +"<br>";
strTxt+="Context String:"+Context.Items["Context"].ToString() +"<br>";
strTxt+=oForm.TestFun() +"<br>";
Literal1.Text =strTxt;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
补充说明,就是Transfer方法的第二个参数指示是否保留页面的Form和QuerryString的值,你可以试着把它设为False,则在WebForm2中将读不到TextBox1的值。
相关文章:
- · Asp.net动态生成html页面
- · Csharp+Asp.net系列教程(六)
- · Csharp+Asp.net系列教程(五)
- · 将一个图片按比例缩放显示在一个Frame中。
- · .Net在SqlServer中的图片存取技术
- · 充分利用ASP.NET缓存提高站点性能
- · 如何获得一个表的结构信息
- · ASP.NET 数据访问类
- · 如何在ASP.NET中显示数据库中的数据
- · Csharp+Asp.net系列教程(四) (2)
- · Csharp+Asp.net系列教程(四)(1)
- · 解决.net开发问题的最终法宝
- · 如何开发高性能的 ASP.NET 应用程序
- · asp和asp.net共享session解决办法
- · 实现自己的ASP.NET宿主系统
- · 在asp.net下将log4net配置成可log到ms sql
- · 越过调试这道槛——ASP.NET无法调试问题剖析
- · 在ASP.NET中实现MVC模式(五)
- · 在ASP.NET中实现MVC模式(四)
- · 在ASP.NET中实现MVC模式(二)
- · 在ASP.NET中实现MVC模式(一)
- · ASP.NET中根据XML动态创建并使用WEB组件(三)
- · ASP.NET中根据XML动态创建并使用WEB组件(二)
- · ASP.NET中根据XML动态创建并使用WEB组件(一)
- · 开发基于Web的CSS设计器
- · 用ImessageFilter接口实现截获键盘消息
- · 窗体启动特效
- · Microsoft Visual Studio .NET 2003制作安装程序
- · 实现基于事件通知的.Net套接字
- · Programming MS Office 2000 Web Components第一章第三节
- · WalkThrough : SharePoint WebPart入门指南全5辑
- · .Net WinForm学习笔记
- · 在IE浏览器中使用Windows窗体控件(三)
- · 在IE浏览器中使用Windows窗体控件(二)
- · 在IE浏览器中使用Windows窗体控件(一)
- · 基于ASP.NET实现全球化
- · Asp.net动态生成html页面
- · 可以搜索的ComboBox----
