Check Existence of QueryString

Discussion in 'ASP General' started by Keith, Jan 31, 2005.

  1. Keith

    Keith Guest

    What is the easiest way to check if a particular QueryString exists?

    I want to know if the QueryString was ever passed rather than whether it
    contains a value or not.
     
    Keith, Jan 31, 2005
    #1
    1. Advertising

  2. Keith

    McKirahan Guest

    "Keith" <@.> wrote in message news:e#...
    > What is the easiest way to check if a particular QueryString exists?
    >
    > I want to know if the QueryString was ever passed rather than whether it
    > contains a value or not.
    >


    What's the difference?

    If Request.QueryString() <> "" Then {whatever}
     
    McKirahan, Jan 31, 2005
    #2
    1. Advertising

  3. Keith

    Evertjan. Guest

    Keith wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    > What is the easiest way to check if a particular QueryString exists?
    >
    > I want to know if the QueryString was ever passed rather than whether
    > it contains a value or not.



    http://localhost/test.asp?qwerty=
    and
    http://localhost/test.asp?a=1&qwerty=zzz

    using test.asp:

    <%
    response.write instr(request.querystring,"qwerty=")>0
    %>

    will both write:

    True

    =========================================

    http://localhost/test.asp?qwertXy=7

    will write:

    False


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jan 31, 2005
    #3
  4. Keith

    Mark Schupp Guest

    Not to pick nits, and probably not a concern to the original poster but

    test.asp?newdata=xxx
    test.asp?morenewdata=yyy

    would both get hits for "newdata="

    If that is a possibility then a more complex condition must be checked.
    Something like the following (not tested, may need tweaking)

    lcase(left(request.querystring, len("newdata=")))="newdata=" Or _
    instr(request.querystring,"&newdata=")>0

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Evertjan." <> wrote in message
    news:Xns95EFAB3CA85B6eejj99@194.109.133.29...
    > Keith wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    > > What is the easiest way to check if a particular QueryString exists?
    > >
    > > I want to know if the QueryString was ever passed rather than whether
    > > it contains a value or not.

    >
    >
    > http://localhost/test.asp?qwerty=
    > and
    > http://localhost/test.asp?a=1&qwerty=zzz
    >
    > using test.asp:
    >
    > <%
    > response.write instr(request.querystring,"qwerty=")>0
    > %>
    >
    > will both write:
    >
    > True
    >
    > =========================================
    >
    > http://localhost/test.asp?qwertXy=7
    >
    > will write:
    >
    > False
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
     
    Mark Schupp, Jan 31, 2005
    #4
  5. "Keith" <@.> wrote in message
    news:e%...
    > What is the easiest way to check if a particular QueryString exists?
    >
    > I want to know if the QueryString was ever passed rather than whether it
    > contains a value or not.
    >


    Response.Write IsEmpty(Request.Querystring("val"))
     
    Chris Hohmann, Jan 31, 2005
    #5
  6. Chris Hohmann wrote:
    > Response.Write IsEmpty(Request.Querystring("val"))


    More to the point, Request.QueryString("val") is an *object*, and one with a
    property already suitable for this task:

    Request.Querystring("val").Count

    The .Count property will return 0 if the parameter is not present and 1 (or
    more) if present.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Feb 5, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    1
    Views:
    432
    John Timney \(Microsoft MVP\)
    Oct 18, 2003
  2. TaeHo Yoo
    Replies:
    3
    Views:
    5,957
    John Timney \(Microsoft MVP\)
    Oct 20, 2003
  3. CK
    Replies:
    5
    Views:
    24,108
    Lars-Inge T√łnnessen \(VJ# MVP\)
    Mar 21, 2006
  4. Replies:
    3
    Views:
    2,941
    Gordon Beaton
    Apr 17, 2006
  5. Andy B.
    Replies:
    1
    Views:
    350
    Alexey Smirnov
    Feb 6, 2009
Loading...

Share This Page