if(Request.QueryString!= null && Request.QueryString.Count>0){
//some piece of code.
}
Thursday, March 17, 2011
Check QueryString for Null
If you need to determine whether the Request.QueryString is null and take some action depending on the result, it is not enough to check for null. QueryString is an HttpValueCollection type, so even if the Request.Url does not have a query string appended to it, the value of the collection is not going to be null. The proper way to check if the query string contains anything is to check for null and the Count property as well:
Subscribe to:
Post Comments (Atom)
good post
ReplyDeleteI have right now copied this into my code :)
ReplyDeleteThat was the whole idea!
ReplyDeleteVery nice.Thanks.
ReplyDeletevery helping code ,it helped me a lot thanks :)
ReplyDelete