Check Existence of QueryString

K

Keith

What is the easiest way to check if a particular QueryString exists?

I want to know if the QueryString was ever passed rather than whether it
contains a value or not.
 
M

McKirahan

Keith said:
What is the easiest way to check if a particular QueryString exists?

I want to know if the QueryString was ever passed rather than whether it
contains a value or not.

What's the difference?

If Request.QueryString() <> "" Then {whatever}
 
E

Evertjan.

Keith wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
What is the easiest way to check if a particular QueryString exists?

I want to know if the QueryString was ever passed rather than whether
it contains a value or not.


http://localhost/test.asp?qwerty=
and
http://localhost/test.asp?a=1&qwerty=zzz

using test.asp:

<%
response.write instr(request.querystring,"qwerty=")>0
%>

will both write:

True

=========================================

http://localhost/test.asp?qwertXy=7

will write:

False
 
M

Mark Schupp

Not to pick nits, and probably not a concern to the original poster but

test.asp?newdata=xxx
test.asp?morenewdata=yyy

would both get hits for "newdata="

If that is a possibility then a more complex condition must be checked.
Something like the following (not tested, may need tweaking)

lcase(left(request.querystring, len("newdata=")))="newdata=" Or _
instr(request.querystring,"&newdata=")>0
 
C

Chris Hohmann

Keith said:
What is the easiest way to check if a particular QueryString exists?

I want to know if the QueryString was ever passed rather than whether it
contains a value or not.

Response.Write IsEmpty(Request.Querystring("val"))
 
D

Dave Anderson

Chris said:
Response.Write IsEmpty(Request.Querystring("val"))

More to the point, Request.QueryString("val") is an *object*, and one with a
property already suitable for this task:

Request.Querystring("val").Count

The .Count property will return 0 if the parameter is not present and 1 (or
more) if present.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top