QueryString Exists!

A

Adam Knight

Can some one tell me how on earth i find out whether a querystring exists.
In classic asp I would do the following.

If(Request.QueryString("test").Count = 0) The Response.Write("QueryString
does not exist!")

Cheers,
Adam
 
S

Steve Lutz

There's 2 ways that I use, depending on the circumstances: (this is C#)

1) If you just want to know if it exists:
if (Request.QueryString["xxxx"] != null)
{
// it exists
}
else
{
// it doesn't
}

2) If you want to do something with it during the same test:
int parameterValue = 0;
try
{
parameterValue = Convert.ToInt32(Request.QueryString["xxxx"]);
}
catch
{
// doesn't exist, or wasn't a number
}
 
K

Ken Dopierala Jr.

Hi Adam,

I always do the following:

If (Request("test") = Nothing) Then
Response.Write("QueryString does not exist!")
Else
End If

That will get you started. There is probably a good reason not to do it
that way but I don't know what it is off the top of my head. Someone will
let us know. Good luck! Ken.
 
P

Phillip Ian

Wouldn't that be IS Nothing? I thought there was a really good reason
not to use equals with Nothing.
 
J

Jon Paal

If Request.Params("test") Is Nothing Then
label1.text = "QueryString does not exist!"
End if
 
K

Ken Dopierala Jr.

Hi Phillip,

You are right, definitely use Is instead of =. I remember reading something
about not using Request() in place of Request.QueryString() but it was long
ago and I don't remember what the reasoning was. Maybe it only applied to
old ASP and not ASP.Net. Either way, good catch! Ken.
 

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,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top