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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access either post or get data 1

Status
Not open for further replies.

tsdragon

Programmer
Dec 18, 2000
5,133
US
If you don't know for sure whether your program is going to be called with get or post data, you can access either very simply. The usual way way is to leave out which you're referring to (.Form or .QueryString), like:
Code:
Request("formfield")
With this method ASP will scan all of the Request collections for the variable specified. The problem with that method is that it scans all of the Request collections. This can be very inefficient, and can cause problems if your form fields have the same name as variables in other Request collections.

There is another method that also works: find which has data and assign it to another collection, then use that collection. Like this:

Code:
Dim tmpColl
If Request.QueryString <> "" then
  set tmpColl = Request.QueryString
elseif Request.Form <> "" then
  set tmpColl = Request.Form
else
  'there is no form data
end if
response.write "myField is " & tmpColl("myField")
Will access the value of the form field "myField" whether it was passed via get or post.

It may come in handy to know that.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top