Roy*_*nto 2 .net c# asp.net visual-studio
如何在Asp.net中将值从一个表单传递到另一个表单?
你能举个例子吗?
我知道了.感谢大家的回复.
在源头我必须写
protected void btnAdd_Click(object sender, EventArgs e)
{
Session["name"] = textBox.Text;
Server.Transfer("WebForm1.aspx");
}
Run Code Online (Sandbox Code Playgroud)
在目标中我必须写
void Page_Load(object sender, EventArgs e)
{
answer.Text = Session["name"].ToString();
Session.Remove("name");
}
Run Code Online (Sandbox Code Playgroud)
客户端技术:1)查询字符串2)Cookies
查询字符串:用于发送:
string name="abc"; Response.Redirect(" Page2.aspx?name= "+name);
对于获取:在Page2.aspx上
string name=Response.QueryString.GetValue(" name ");
对于cookie,您可以使用发送:
HttpCookie h=new HttpCookie();
h.Name="name";
h.Value="abc";
Response.Cookies.Add(h) ;
获得:
string name = Request.Cookies('name');
服务器端技术:1)会话
用于设置:
Session["Name"] = "Abc";
对于获取:
string str = Session["Name"].ToString();
在Session中,您可以传递任何对象类型.
| 归档时间: |
|
| 查看次数: |
12972 次 |
| 最近记录: |