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.
thenthorn1010Asked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.