Loop round all querystring parameters?

M

Mike

Is it possible to loop round all querystring parameters in a web page (i.e.
access them without hardcoding them)?

I want to do this because I have a page that has different querystring
variables passed into it depending on the content of the calling page.
 
M

Mike

Mike said:
Is it possible to loop round all querystring parameters in a web page
(i.e. access them without hardcoding them)?

I want to do this because I have a page that has different querystring
variables passed into it depending on the content of the calling page.

P.S. That would be querystring variables with names like

test_page.asp?var1=3&var2=2&var6=8&var9=6

How do I access var1, var2, var6 and var9 without hard coding them?
 
B

Bob Barrows [MVP]

Mike said:
P.S. That would be querystring variables with names like

test_page.asp?var1=3&var2=2&var6=8&var9=6

How do I access var1, var2, var6 and var9 without hard coding them?

The following works with all the Request collections (Form, ServerVariables,
Querystring):

dim key
for each key in Request.Querystring
Response.Write key & ": " & Request.Querystring(key) & "<BR>"
next

HTH,
Bob Barrows
 
P

Phill. W

Mike said:
Is it possible to loop round all querystring parameters in a web page (i.e.
access them without hardcoding them)?

Request.QueryString doesn't support a Contents property (like
Session) so you'll probably have to pull the QueryString apart
yourself, something like :

sQS = Request.QueryString
For Each eItem in Split( sQS, "&" )
sName = Left( eItem, Instr( eItem & "=", "=" ) - 1 )
Response.Write sName _
& " = " & Request.QueryString( sName ) _
& "<br>"
Next

Watch out; you may /still/ fall foul of URLEncode'd parameter names.

HTH,
Phill W.
 
P

Phill. W

Bob Barrows said:
.. . .
The following works with all the Request collections (Form,
ServerVariables, Querystring):

dim key
for each key in Request.Querystring
Response.Write key & ": " & Request.Querystring(key) & "<BR>"
next

Now how on Earth did I forget that???

Regards,
Phill W.
 
M

Mike

Bob Barrows said:
The following works with all the Request collections (Form,
ServerVariables, Querystring):

dim key
for each key in Request.Querystring
Response.Write key & ": " & Request.Querystring(key) & "<BR>"
next

HTH,
Bob Barrows

Absolutely perfect, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top