如何在Asp.net中将值从一个表单传递到另一个表单

如何在Asp.net中将值从一个表单传递到另一个表单?

你能举个例子吗?


我知道了。 感谢大家的回复。

在源头我必须写

protected void btnAdd_Click(object sender, EventArgs e) { Session["name"] = textBox.Text; Server.Transfer("WebForm1.aspx"); } 

在目标中我必须写

 void Page_Load(object sender, EventArgs e) { answer.Text = Session["name"].ToString(); Session.Remove("name"); } 

客户端技术:1)查询字符串2)Cookies

查询字符串:用于发送:

string name="abc"; Response.Redirect(" Page2.aspx?name= "+name);

For Getting:On Page2.aspx string name=Response.QueryString.GetValue(" name ");

对于cookie,您可以使用发送: HttpCookie h=new HttpCookie(); h.Name="name"; h.Value="abc"; Response.Cookies.Add(h) ; HttpCookie h=new HttpCookie(); h.Name="name"; h.Value="abc"; Response.Cookies.Add(h) ;

获取: string name = Request.Cookies('name');

服务器端技术:1)会话

对于设置: Session["Name"] = "Abc";

For Getting: string str = Session["Name"].ToString();

在Session中,您可以传递任何对象类型。