Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: Passing local value from page1.asp to page2.asp

Status
Not open for further replies.

Creeder

Programmer
Jul 5, 2000
110
MY
Hi,

What would be the best way to pass a local variable from page1.asp to page2.asp? Should i create a session variable in page1, assign the value and the retrive the value in page2? or is there another method. I am using POST method by the way.


THanks.
 
Some ways to do it:
1. Session variable
2. hidden field in form
3. part of querystring
4. save in database table

Depends on security required for the variable and length of data.

If security is an issue, ie. you don't want anyone to be able to see it, then 2 and 3 are out.

If you don't want anyone to be able to change it (between pages), then 3 is out, cuz they have access to anything in the querystring.

If the variable could be a large amount of data, 3 is no good, since there's a limit on how long the querystring can be, and 1 may not be the best option as it uses up memory.

Also, if not all users will have cookies enabled, 1 is not good, since session variables require cookies enabled.

The most secure and most flexible is using a database, but if none of the above conditions apply, session variables are suitable also.
 
The easiest way (if the information isn't critical), would be to do a combination of the POST and GET methods.

For example, say in PAGE1.ASP you defined a variable "strName" and filled it with the value "John Smith" from a form field. Using POST will by its nature not include this in the URL's querystring, but you can to some degree force the issue.

and then at the bottom of your page use

Response.Redirect ("page2.asp?filename=" & strName)

...and then you have the value of strName for use again in your page. It's a rather low-budget way of persisting a value...but it works.

Lobstah is absolutely right, though...if this is an e-commerce type of app (like a shopping cart), I wouldn't recommend it...unless over some sort of SSL connection...but this is another issue in itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top