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

  • Thread starter Thread starter ABC
  • Start date Start date
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)
 
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
 
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.
 
Back
Top