• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

How to Pass Parameters from One ASPX page to Another And How to Read Those Values that Are Passed

I have built a website that has some textboxes on the first web page that needs to pass the data to second ASP.NET page. I was wondering if someone could tell me how you would go about passing a couple of parameters, for instance gallons, price, and time, in a url from one page to another. (for the question, assume that the first page is going from http://page1.aspx to http://page2.aspx. [I am new to ASP.NET/C# programming, so I apologize in advance if I need a little bit more clarification in advance on an answer that is given by someone in this forum.] The data that is being passed to a second page needs to be read by the second page using C#/ASP.NET, and I was also wondering if someone could let me know how to extract those values that were passed from the first page to the second page.)

Thank you in advance for your time and your help.
0
thenthorn1010
Asked:
thenthorn1010
  • 3
3 Solutions
 
Friman001Commented:
You can use the Session array to pass between pages.  I used it to pass a multi-line textbox worth of text to another page.

Page with textbox that the data is entered into (put in codebehind file, of course!):
Session["varName"] = this.TextBox1.Text.ToString();

Open in new window


Page that you want to use the data in:
this.TextBox1.Text = Session["varName"].ToString();

Open in new window

0
 
Friman001Commented:
If you want to keep the format of the text or the text is large or confidential, you want to use the session variable.  Otherwise, you can use the query string like this:

this.HyperLink1.NavigateUrl = "~/Folder/Test.aspx?variablename=" + variableName + "&variablename2=" + variableName2;

Open in new window

and then to call it on the page you navigate to:
string holder = Request.QueryString["variablename".ToString();
string holder2 = Request.QueryString["variablename2"];

Open in new window

0
 
Friman001Commented:
I forgot a "]" in the second example!  Sorry!  It should be:
string holder = Request.QueryString["variablename"].ToString();
string holder2 = Request.QueryString["variablename2"];

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now