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.
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 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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.