How can I know the QueryString has a keyword or not?

T

Teemu Keiski

Hi,

Request.QueryString collection itself isn't probably populated if there
isn't both key abd value (.aspx?key=value) but you should be able to inspect
the qs as normal string.

For example

Dim hasKey As Boolean = (Request.QueryString.ToString().IndexOf("key") > -1)
 
R

Riki

Teemu said:
Hi,

Request.QueryString collection itself isn't probably populated if
there isn't both key abd value (.aspx?key=value) but you should be
able to inspect the qs as normal string.

For example

Dim hasKey As Boolean =
(Request.QueryString.ToString().IndexOf("key") > -1)

Most of the time, this will be correct, but you may get false hits with this
method.

For instance, when checking for the key "ID", this querystring will
erroneously satisfy your condition:
www.domain.com/index.aspx?name=didi
 
O

OHM \( One Handed Man \)

or

If Request.Params.GetKey("KeyName") Is Nothing Then

Response.Write("The key 'KeyName' does not exist")

End If


--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net



Klaus H. Probst said:
ABC said:
http://mysite.com/iijjkk.aspx?added

I want to know the querystring has 'added' keyword or not.

From within an ASP page, just use Request.QueryString:

string k = Request.QueryString["added"];

If the parameter was there, k will be non-null.
 

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

Top