[asp.net] 页面传值方法小记

两个网页1.aspx和2.aspx,为第二个网页传值;
第一种方法用Session传值:


在1.aspx中:
this.Session["number"]=this.TextBox.Text;
Response.redirect("2.aspx");


在2.aspx中让Session输出:
if(this.session["number"]!=null)
this.Lable.Text=this.Session["number"];


第二种方法用Response.Redirect()传值(不提倡使用):


在1.aspx中:
this.Response.Redirect("2.aspx?name",this.TextBox.Text);
在2.aspx中:
if(this.response.querystring["name"]!=null)
this.Lable.Text=This.Response.querystring["name"];




第三种方法用cookies方法:


在1.aspx中定义一cookies为它赋值:
httpcookies cookie=new httpcookies("name");
cookie.value=this.textbox.text;
reponse.cookies.add(cookie);
response.redirect("2.aspx");


在2.aspx的输出:
if(request.cookies["name"]!=null)
Lable.text=request.cookies["name"].value

原文地址:https://www.cnblogs.com/ishibin/p/2374855.html