垃圾

dyengying 2009-03-10 02:39:25
使用Session变量传值是一种最常见的方式了,此中方式不仅可以把值传递到下一个页面,还可以交叉传递到多个页面,直至把Session变量的值removed后,变量才会消失。举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
运行,即可看到传递后的结果了。

...全文
70 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dnpyy 2009-03-10
  • 打赏
  • 举报
回复
O(∩_∩)O~
Atai-Lu 2009-03-10
  • 打赏
  • 举报
回复
.........
搬运工865 2009-03-10
  • 打赏
  • 举报
回复
~!@#¥%……&*()

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧