如何在 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
查询字符串: 对于发送:
字符串名称="abc"; Response.Redirect("Page2.aspx?name= "+name);
获得:
在 Page2.aspx 上
string name=Response.QueryString.GetValue("name");
对于您可以使用的 cookie
发送:
HttpCookie h=new HttpCookie();
h.Name="姓名";
h.Value="abc";
Response.Cookies.Add(h) ;
得到:
string name = Request.Cookies('name');
服务器端技术: 1) session
对于设置:
Session["Name"] = "Abc";
获得:
string str = Session["Name"].ToString();
在 session 中,您可以传递任何对象类型。
关于c# - 如何在 Asp.net 中将值从一种形式传递到另一种形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6746860/