PC Review


Reply
Thread Tools Rate Thread

Check existance of a querystring variable

 
 
Imran Aziz
Guest
Posts: n/a
 
      9th Aug 2005
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.


 
Reply With Quote
 
 
 
 
Grant Merwitz
Guest
Posts: n/a
 
      9th Aug 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Imran Aziz
Guest
Posts: n/a
 
      9th Aug 2005
Wonderful, thanks a lot Grant.
Imran
"Grant Merwitz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Existance of a Static variable. Duggi Microsoft C# .NET 8 22nd Sep 2008 05:58 PM
Existance of a Static variable. Duggi Microsoft C# .NET 1 22nd Sep 2008 01:58 PM
Check on existance Lodewijk Microsoft Access Forms 2 14th Nov 2004 09:13 PM
Check on existance Lodewijk Microsoft Access Getting Started 2 14th Nov 2004 09:13 PM
Check on existance Lodewijk Microsoft Access Macros 2 14th Nov 2004 09:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 AM.