By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Checking Query String

P: n/a
A.M
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryString["id"]!=null)
{
Label1.Text= Request.QueryString["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing
some better method in QueryString?

Thanks,
Alan
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QueryString["id"] == null ? "NoId" :
Requesty.QueryString["id"];
"A.M" <no*****@online.nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryString["id"]!=null)
{
Label1.Text= Request.QueryString["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing
some better method in QueryString?

Thanks,
Alan

Nov 18 '05 #2

P: n/a
A.M
Thanks for help

So QueryString doesn't have any method for checking the existance of a key?

Alan
"Marina" <so*****@nospam.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QueryString["id"] == null ? "NoId" :
Requesty.QueryString["id"];
"A.M" <no*****@online.nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryString["id"]!=null)
{
Label1.Text= Request.QueryString["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing some better method in QueryString?

Thanks,
Alan


Nov 18 '05 #3

P: n/a
Have you looked at the .NET documentation? It fully documents all of this -
it is a lot faster to spend 1 minute reading the documentation, then waiting
for hours for someone to respond to your post. You would also probably end
up learning a lot of other useful things.

To answer your question, no there is not a method that will tell if a key
exists. There is a Keys collection - but you would have to loop through it
and check to see if the current key is the same as the one you are looking
for.

This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.

"A.M" <no*****@online.nospam> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
Thanks for help

So QueryString doesn't have any method for checking the existance of a key?
Alan
"Marina" <so*****@nospam.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QueryString["id"] == null ? "NoId" :
Requesty.QueryString["id"];
"A.M" <no*****@online.nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,

To check if QueryString contains a key I compaire it with null like this code:

if (Request.QueryString["id"]!=null)
{
Label1.Text= Request.QueryString["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing some better method in QueryString?

Thanks,
Alan



Nov 18 '05 #4

P: n/a
A.M
Thank you for help.

Yes I did have a look at documentation and also searched couple of ASP.NET
portals.
I couldn't find anything.

Sometimes there are techniques that you can not find directly from
documentation. That is when you look for experienced people to ask them.

Alan

"Marina" <so*****@nospam.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl...
Have you looked at the .NET documentation? It fully documents all of this - it is a lot faster to spend 1 minute reading the documentation, then waiting for hours for someone to respond to your post. You would also probably end
up learning a lot of other useful things.

To answer your question, no there is not a method that will tell if a key
exists. There is a Keys collection - but you would have to loop through it
and check to see if the current key is the same as the one you are looking
for.

This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.

"A.M" <no*****@online.nospam> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
Thanks for help

So QueryString doesn't have any method for checking the existance of a

key?

Alan
"Marina" <so*****@nospam.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QueryString["id"] == null ? "NoId" :
Requesty.QueryString["id"];
"A.M" <no*****@online.nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> To check if QueryString contains a key I compaire it with null like this > code:
>
> if (Request.QueryString["id"]!=null)
> {
> Label1.Text= Request.QueryString["id"];
> }
> else
> {
> Label1.Text= "NoId";
> }
>
> Is it the best way to do see if QueryString contains a key or I am

missing
> some better method in QueryString?
>
> Thanks,
> Alan
>
>



Nov 18 '05 #5

P: n/a
Hello!
This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.


I agree, but I would have liked to see the .Exists() or .Contains() method
as well.

--
venlig hilsen / with regards
anders borum
--
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.