在两个页面之间传递信息
来源:互联网 发布:中航软件 led魔宝 编辑:程序博客网 时间:2024/04/28 18:10
在asp.net不同页面之间传值的方法主要有三种:
(1)用querystring
方法:在vs2005中新建asp.net网站(发送端),在页面上添加button,两个TextBox,代码如下:
(2)使用session变量
(3)使用server.transfer
(1)用querystring
方法:在vs2005中新建asp.net网站(发送端),在页面上添加button,两个TextBox,代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string url;
url = "http://localhost/look1/Default.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
Response.Redirect(url);
}
再建接收端页面,在页面上添加两个TextBox,代码如下:{
string url;
url = "http://localhost/look1/Default.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
Response.Redirect(url);
}
TextBox1.Text = Request.QueryString["name"];
TextBox2.Text = Request.QueryString["email"];
TextBox2.Text = Request.QueryString["email"];
(2)使用session变量
private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Server.Transfer("http://localhost/look1/Default.aspx");
}
目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
TextBox1.Text=Session["name"].ToString();
TextBox2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Server.Transfer("http://localhost/look1/Default.aspx");
}
目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
TextBox1.Text=Session["name"].ToString();
TextBox2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
(3)使用server.transfer
源页面代码:
把以下的代码添加到页面中
public string Name
{
get
{
return TextBox1.Text;
}
}
public string EMail
{
get
{
return TextBox2.Text;
}
}
然后调用Server.Transfer方法
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
WebForm1 wf1;
wf1=(WebForm1)Context.Handler;
TextBox1.Text=wf1.Name;
TextBox2.Text=wf1.EMail;
}
当然,在同一个解决方案里的不同页面之间传值就更简单了,只需将url改为页面名(如:Default2.aspx)就OK了!试试看
把以下的代码添加到页面中
public string Name
{
get
{
return TextBox1.Text;
}
}
public string EMail
{
get
{
return TextBox2.Text;
}
}
然后调用Server.Transfer方法
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
WebForm1 wf1;
wf1=(WebForm1)Context.Handler;
TextBox1.Text=wf1.Name;
TextBox2.Text=wf1.EMail;
}
- 在两个页面之间传递信息
- 在两个页面之间传递信息
- 如何在两个页面之间传递DataTable
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值的方法
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值
- 在两个ASP.NET页面之间传递值三种方法
- 在两个ASP.NET页面之间传递值三种方法
- 通过分区(Partition)提升MySQL性能
- .NET Compact Framework 1.0 下实现抓屏
- Thoughts on an OpenDocument Toolkit
- 学习ADO.NET
- 金融领域UNIX网络系统的安全管理策略
- 在两个页面之间传递信息
- Thinking in AJAX -- 基于AJAX的WEB设计
- Test
- 十一.结 构 与 联 集
- 一个图片按钮类
- 关于无法找到资源程序集(Could not find resource assembly)
- WebSphere Portal中多层Placebar主题的开发(二)
- 十二.档案之输入与输出
- 报告SAS LICENSE使用情况