if request.querystring('Id") = ""

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guoqi Zheng

    if request.querystring('Id") = ""

    On my application, I need to have different action based on the pass in
    query string. When the query string is not presented, I try to use

    If request.queryst ring("id") ="" THEN ......

    This is what I did in trational asp, however if I did abov in ASP.NET, I
    always got an error of "Object reference not set to an instance of an
    object. "

    How should I solve the problem?

    --
    Kind regards

    Guoqi Zheng
    guoqi AT meetholland dot com




  • Ken Dopierala Jr.

    #2
    Re: if request.queryst ring('Id") = ""

    Hi Guoqi,

    You can do two things:

    1. Use Request("id") = "".
    2. Test for Nothing:
    If Not (Request.QueryS tring("id") Is Nothing) Then ....

    Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:

    If you sign up under me and need help, email me.

    "Guoqi Zheng" <no@sorry.nl> wrote in message
    news:eRBS4L8sEH A.3052@tk2msftn gp13.phx.gbl...[color=blue]
    > On my application, I need to have different action based on the pass in
    > query string. When the query string is not presented, I try to use
    >
    > If request.queryst ring("id") ="" THEN ......
    >
    > This is what I did in trational asp, however if I did abov in ASP.NET, I
    > always got an error of "Object reference not set to an instance of an
    > object. "
    >
    > How should I solve the problem?
    >
    > --
    > Kind regards
    >
    > Guoqi Zheng
    > guoqi AT meetholland dot com
    > Http://www.meetholland.com
    >
    >
    >[/color]


    Comment

    • Mark Fitzpatrick

      #3
      Re: if request.queryst ring('Id&quot;) = &quot;&quot;

      In VBScript there is essentially only one datatype, the variant datatype
      which changes behavior based upon how it is referenced. That's why a
      variable can be used to perform mathematical functions in one case, then
      later be treated as a string. In .Net languages there is no variant so
      things behave a little different. The Request.Queryst ring[key] returns an
      object. When the key is not found, it returns null instead. An empty string
      is not a null value since a null is a very special case all by itself. You
      can test to see if the key is null first. You'll have to forgive me, but I
      haven't played with VB in a while so I'll show the C# code instead and you
      should be able to recognize how to do it in VB.

      if(Request.Quer ystring["id"] == null)

      Hope this helps,
      Mark Fitzpatrick
      Microsoft MVP - FrontPage

      "Guoqi Zheng" <no@sorry.nl> wrote in message
      news:eRBS4L8sEH A.3052@tk2msftn gp13.phx.gbl...[color=blue]
      > On my application, I need to have different action based on the pass in
      > query string. When the query string is not presented, I try to use
      >
      > If request.queryst ring("id") ="" THEN ......
      >
      > This is what I did in trational asp, however if I did abov in ASP.NET, I
      > always got an error of "Object reference not set to an instance of an
      > object. "
      >
      > How should I solve the problem?
      >
      > --
      > Kind regards
      >
      > Guoqi Zheng
      > guoqi AT meetholland dot com
      > Http://www.meetholland.com
      >
      >
      >[/color]


      Comment

      • Steve C. Orr [MVP, MCSD]

        #4
        Re: if request.queryst ring('Id&quot;) = &quot;&quot;

        Try this syntax:

        If IsNothing(Reque st.Querystring( "id")) OrElse Request.Queryst ring("id")=""
        Then...

        --
        I hope this helps,
        Steve C. Orr, MCSD, MVP



        "Guoqi Zheng" <no@sorry.nl> wrote in message
        news:eRBS4L8sEH A.3052@tk2msftn gp13.phx.gbl...[color=blue]
        > On my application, I need to have different action based on the pass in
        > query string. When the query string is not presented, I try to use
        >
        > If request.queryst ring("id") ="" THEN ......
        >
        > This is what I did in trational asp, however if I did abov in ASP.NET, I
        > always got an error of "Object reference not set to an instance of an
        > object. "
        >
        > How should I solve the problem?
        >
        > --
        > Kind regards
        >
        > Guoqi Zheng
        > guoqi AT meetholland dot com
        > Http://www.meetholland.com
        >
        >
        >[/color]


        Comment

        • Karl

          #5
          Re: if request.queryst ring('Id&quot;) = &quot;&quot;

          To add my $0.02, in .Net a null string evuluates true when compared to an
          empty string :
          if nothing = "" then
          'this will always be true
          end if

          so checking for both is pointless.

          if you simply want to check for not null/nothing:

          if NOT Request.QuerySt ring("id") = nothing then
          ...
          end if

          if you want to check for not null/nothing as well as not an empty string:

          dim id as string = Request.QuerySt ring("id")
          IF NOT id IS NOTHING ANDALSO NOT id.length = 0 Then
          'id is an actual string
          END IF

          In VB.Net you absolutely must use AndAlso instead of just And in the above
          code, else it'll crash (and you should always be using AndAlso anyways).

          checking for a string length = 0 vs comparing to an empty string is a
          microsoft recommendation and will show up in FxCop.

          Karl
          --
          MY ASP.Net tutorials
          Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



          "Steve C. Orr [MVP, MCSD]" <Steve@Orr.ne t> wrote in message
          news:%23I1l729s EHA.2668@TK2MSF TNGP12.phx.gbl. ..[color=blue]
          > Try this syntax:
          >
          > If IsNothing(Reque st.Querystring( "id")) OrElse[/color]
          Request.Queryst ring("id")=""[color=blue]
          > Then...
          >
          > --
          > I hope this helps,
          > Steve C. Orr, MCSD, MVP
          > http://Steve.Orr.net
          >
          >
          > "Guoqi Zheng" <no@sorry.nl> wrote in message
          > news:eRBS4L8sEH A.3052@tk2msftn gp13.phx.gbl...[color=green]
          > > On my application, I need to have different action based on the pass in
          > > query string. When the query string is not presented, I try to use
          > >
          > > If request.queryst ring("id") ="" THEN ......
          > >
          > > This is what I did in trational asp, however if I did abov in ASP.NET, I
          > > always got an error of "Object reference not set to an instance of an
          > > object. "
          > >
          > > How should I solve the problem?
          > >
          > > --
          > > Kind regards
          > >
          > > Guoqi Zheng
          > > guoqi AT meetholland dot com
          > > Http://www.meetholland.com
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...