【问题标题】:How can I pass values from one form to another in Asp.net如何在 Asp.net 中将值从一种形式传递到另一种形式
【发布时间】:2011-10-08 11:29:54
【问题描述】:

如何在 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");
}

【问题讨论】:

  • 你能再具体一点吗?
  • 我正在开发 asp.net 应用程序。我有 2 个页面称为 default.aspx 和另一个页面。如果我在 Defalut.aspx 的文本框中输入内容,它应该会显示在第二页。

标签: c# .net asp.net visual-studio


【解决方案1】:

客户端技术: 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 中你可以传递任何对象类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-23
    • 2015-06-06
    • 2020-03-10
    • 2012-03-11
    相关资源
    最近更新 更多