如何传递的值从一种形式到另Asp.net [英] How can I pass values from one form to another in Asp.net

查看:132
本文介绍了如何传递的值从一种形式到另Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何传递值从一种形式到另一个Asp.net?

您可以请给我一个例子吗?


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

在源我有写

 保护无效btnAdd_Click(对象发件人,EventArgs的)
{
    会话[名称] = textBox.Text;
    Server.Transfer的(WebForm1.aspx);
}
 

和目标我必须写

 无效的Page_Load(对象发件人,EventArgs的)
{
    。answer.Text =会话[名称]的ToString();
    Session.Remove(姓名);
}
 

解决方案

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

查询字符串: 发送:

字符串名称=ABC;的Response.Redirect(?Page2.aspx名=+姓名);

有关获取: 在Page2.aspx 字符串名称= Response.QueryString.GetValue(姓名);

有关cookies,您可以使用 发送:  的HttpCookie H =新的HttpCookie(); h.Name =名; h.Value =ABC; Response.Cookies.Add(H);

获取: 字符串名称= Request.Cookies时('名');

服务器端技术: 1)会话

有关设置: 会话[名称] =ABC;

有关获取: 字符串str =会话[名称]的ToString();

在会话可以传递任何对象类型。

How can I pass values from one form to another in Asp.net?

Can you please give me an example?


I got it. Thanks for everyone for replying.

In source i have to write

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

and in target i have to write

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

解决方案

Client side technology: 1)Query String 2)Cookies

Query String: For SEnding:

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

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

For cookies you can use Sending: HttpCookie h=new HttpCookie(); h.Name="name"; h.Value="abc"; Response.Cookies.Add(h) ;

Getting: string name = Request.Cookies('name');

Server Side Technology: 1)Session

For Setting: Session["Name"] = "Abc";

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

In Session you can pass any object type.

这篇关于如何传递的值从一种形式到另Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆