Checking for Query Strings in ASP.NET

Posted by mdrisser on 2010/01/19 under ASP.NET, Development, PHP | Be the First to Comment

Introduction: I am a PHP developer who has recently begun learning ASP.NET. Its an interesting journey to say the least. I’ve decided to share with you ways I’ve found to do things in ASP.NET that are second nature to me in PHP. They may not always be the most effective, or the most correct, but I am still learning. If you know of a better way to do something I post, by all means let me know in the comments.

In PHP we often check to see if a query string has been set through the use of the $POST or $GET variables and checking to see if they are set:

if(isset($_POST["q"]) {
    // Do some stuff
}

But how to do this in ASP.NET? Well, the answer is quite simple. To check to see if there is a query string, simply do this:

if(Request.QueryString.HasKeys()) {
    // Do some stuff
}

As I mentioned above, I’m still learning ASP.NET. Besides I subscribe to the TIMTOWTDI principal: There Is More Than One Way To Do It. If you have another and/or better way, leave me a comment.

  • Share/Bookmark

Add A Comment