Thursday, November 18, 2004

QueryString - A Cool tip

The exciting thing about my work is that I learn new things. Whenever I learn new things, I get excited :-)

Today I learnt some exciting (weird, may I call it) thing about using QueryStrings in ASPX pages.

When you pass a querystring in an ASP page, and you need to check the same, you go ahead and do:


If Request.QueryString("whatever") = "whatever" Then
'Do Whatever
End If




If the page do not get the querystring "whatever", it wouldn't mind.
BUT, in ASP.NET, the page would throw an expception (Object reference not set to an instance of an object)!!!
So, if you have a scenario in your application where you might not pass the querystring, you might want to do something on this line:

If Not (Request.QueryString("whatever") Is Nothing) AndAlso Request.QueryString("whatever") = "whatever" Then 
'Do Whatever
End If

(MAY BE THIS WAS TO REMIND ME: .NET IS ALL ABOUT OBJECTS. IF THERE IS NO OBJECT, YOU AIN'T GONNA DO A DAMN!)

Have you ever encountered such cases? What measures did you take to tackle them? Please add your two cents.


1 comment:

  1. Hello,

    You could also try:

    If (Request.QueryString.Get("whatever") <> String.Empty) Then
    'Do something
    End If

    That may work better for you. Also, where are you trying to access the querystring value?

    Brian
    bgmst5@yahoo.com

    ReplyDelete

Cookies, anyone?

  Our application started having integration issues early March this year. Did I say that was intermittent? To add to our confusion, we coul...