从一个页面发送到另一个数据 [英] Send data from one page to another

查看:153
本文介绍了从一个页面发送到另一个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个页面发送表单数据到另一个使用C#ASP.Net。我有两页的Default.aspx和default2.aspx.Here是code我在Default.aspx的:

I am trying to send form data from one page to another using C# ASP.Net. I have two pages default.aspx and default2.aspx.Here is the code I have in default.aspx:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Go" 
    PostBackUrl="~/Default2.aspx" />
<br />

据我所知,到目前为止使用了一项PostBackUrl设置要在其中的数据发送这是正确的页面?

From what I know so far the PostBackUrl is used to set the page in which you want the data to be sent is this correct?

此外,我怎么可以检索发送到Default2.aspx数据?

Also how can I retrieve the data that is sent to Default2.aspx?

推荐答案

您有几种选择,可以考虑

You have a few options, consider


  1. 会话状态

  2. 查询字符串

会话状态

如果你要在页面之间发送数据,则可以考虑使用的会话状态

If you are going to send data between pages, you could consider the use of Session State.

ASP.NET会话状态使您能够存储和检索的值
  用户当用户浏览Web应用程序的ASP.NET页面。 HTTP是
  一个无状态的协议。这意味着,在Web服务器将每个HTTP
  请求一个页面作为一个独立的请求。服务器不保留
  在previous请求中使用的变量值的知识。
  ASP.NET会话状态中识别来自同一浏览器的请求
  在有限的时间窗口为会话,并提供了一​​种方法来持续
  该会话的持续时间变量值。默认情况下,ASP.NET
  会话状态的所有ASP.NET应用程序启用。

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.

最重要的是,很容易!

把数据(例如在default1.aspx)

Put data in (for example on default1.aspx)

Session["FirstName"] = FirstNameTextBox.Text;
Session["LastName"] = LastNameTextBox.Text;

把它弄出来(例如在default2.aspx)

Get it out (for example on default2.aspx)

string firstname = Session["FirstName"] // value of FirstNameTextBox.Text;
string lastname = Session["LastName"] // value of LastNameTextBox.Text; 

查询字符串

如果您正在发送少量数据(比如:id = 4),它可能更实际使用的查询字符串变量。

If you are sending small amounts of data (eg id=4), it may be more practical to use query string variables.

您应探讨使用查询字符串变量,例如

You should explore the use of the query string variables, e.g.

http://www.domain.com?param1=data1&param2=data2

您就可以获取数据出像

string param1 = Request.QueryString["param2"]; // value will be data1
string param2 = Request.QueryString["param2"]; // value will be data2

您可以使用类似<一个href=\"http://stackoverflow.com/questions/349742/how-do-you-test-your-request-querystring-variables\">How测试你的Request.QueryString []变量?来获取数据。

You can use something like How do you test your Request.QueryString[] variables? to get the data out.

如果您不熟悉的查询字符串变量退房他们的维基百科文章

If you are unfamiliar with querystring variables check out their wikipedia article

这篇关于从一个页面发送到另一个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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