Check existance of a querystring variable

I

Imran Aziz

Hello All,
I have ASP.net , C# pages checking for query string variables, the old
ASP has a count property that one could check for each key/value pair to
determine if it is available in the query string or not, but ASP.net does
not have that for each key/value, instead there is a count for all items in
the query string.

Say if I have a query string variable called key1=value1 how do I check if
key1 was set or not?
Thanks a lot in advance.

Imran.
 
G

Grant Merwitz

I do it like this

if(Request.QueryString["key1"] != "" && Request.QueryString["key1"] != null)
{
//Querystring exists
}

And to make this less painful, i also create a static method that i call for
this.

So:

public class Common
{
public static bool HasValue(object o)
{
if (o == null)
{
return false;
}

if (o == System.DBNull.Value)
{
return false;
}

if (o is String)
{
if (((String) o).Trim() == String.Empty)
{
return false;
}
}

return true;
}
}
 
I

Imran Aziz

Wonderful, thanks a lot Grant.
Imran
Grant Merwitz said:
I do it like this

if(Request.QueryString["key1"] != "" && Request.QueryString["key1"] !=
null)
{
//Querystring exists
}

And to make this less painful, i also create a static method that i call
for this.

So:

public class Common
{
public static bool HasValue(object o)
{
if (o == null)
{
return false;
}

if (o == System.DBNull.Value)
{
return false;
}

if (o is String)
{
if (((String) o).Trim() == String.Empty)
{
return false;
}
}

return true;
}
}




Imran Aziz said:
Hello All,
I have ASP.net , C# pages checking for query string variables, the old
ASP has a count property that one could check for each key/value pair to
determine if it is available in the query string or not, but ASP.net does
not have that for each key/value, instead there is a count for all items
in the query string.

Say if I have a query string variable called key1=value1 how do I check
if key1 was set or not?
Thanks a lot in advance.

Imran.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top