Avatar of XPLR
XPLR
 asked on

Passing value from one page to another.

I am trying to pass set of information from one apge to another. Which is a better approach the query string or the session variable? And why.
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
b_levitt

8/22/2022 - Mon
Rick

It just depends on the type and size of the data being passed.

Small information, one page to another, use querystring. Othewise use session variables.

Also, session variables will be available from any page until it is killed or expired.
QueryStrings are used to pass values from just one page to another.

SOLUTION
mrjoltcola

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
b_levitt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
b_levitt

As to the issue with url tampering, i generally use a hash function and append it's digest to the url to confirm against (like a checksum).  However, this was only needed in apps where a security check couldn't be done on the destination page.  Do you have an example of such secure data mrjoltcola?
starlite551

Session variable is more secure way to send data across pages. As user cannot see the actual values as in case of query string. When you have large amount of data you should prefer passing it via a Session variable coz its much flexible and robust and vice versa. two ways of creating Session variables are :  
//1st way..
Session.Add("Key","Value");

//2nd way..
Session["Key"] = "Value";

Open in new window

Here Key must be a string qualifier for the Session variable i.e name of the variable. And Value part is actually of object type which can store any of the two value or reference type. In the above case I have used a String type with value as "Value".
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
starlite551

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
starlite551

The above example assumes that you have a TextBox Control (textBox1) in your first page i.e Default.aspx the value of which you need to send to second page. i.e Default2.aspx
SAMIR BHOGAYTA

Hello, with the use of session variable it more helpful than the query string, Because you have to easily pass the value with the session variable.
ASKER CERTIFIED SOLUTION
b_levitt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.