To read the article online, visit http://www.4GuysFromRolla.com/webtech/faq/Intermediate/faq5.shtml

Passing Variables Between ASP Pages using POST


The previous FAQ described how to pass information from one page to another using the QueryString. To assimilate variables in the QueryString you can either use a form with METHOD="GET" or redirect the user to a URL which looks like:

http://www.myserver.com/myasp.asp?var1=hello&var2=world

You can also pass variables using the form METHOD="POST". This has the effect of "hiding" the parameters passed, since it is done on the server-side as opposed to having the client pass the information string to the server (as in the QueryString example above).

A POSTed form looks identical to a GETed form, except instead of FORM="GET", we put FORM="POST". Here is an example:

<FORM METHOD="POST" ACTION="myasp.asp">
      ... HTML here ...
</FORM>

In the file myasp.asp, we read the data the same way we do for QueryString variables. We just use Request(variablename). For more information on how to read variables using Request, please read the previous FAQ.

You may be wondering why anyone would prefer using a GET over a POST or vice versa. They appear to be identicle. One benefit of a POST is that you can pass nonstandard characters with less hassle than through the QueryString. For example, say that you wanted to pass the string: "Hello     my name is ?&!" Well, passing characters like ?, &, and " " can be cumbersome through the QueryString. When variables will hold such characters, it is often wiser to put them in a POSTed FORM as opposed to a GETed one.

Also, in some older browsers there is a limit to the length of the QueryString. If you need to pass a lot of variables, be sure to not do it through the QueryString.


Article Information
Article Title: Passing Variables Between ASP Pages using POST
Article Author: Scott Mitchell
Article URL: http://www.4GuysFromRolla.com/webtech/faq/Intermediate/faq5.shtml


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers