Loop round all querystring parameters?

Discussion in 'ASP General' started by Mike, Aug 17, 2005.

  1. Mike

    Mike Guest

    Is it possible to loop round all querystring parameters in a web page (i.e.
    access them without hardcoding them)?

    I want to do this because I have a page that has different querystring
    variables passed into it depending on the content of the calling page.
     
    Mike, Aug 17, 2005
    #1
    1. Advertising

  2. Mike

    Mike Guest

    "Mike" <> wrote in message
    news:%...
    > Is it possible to loop round all querystring parameters in a web page
    > (i.e. access them without hardcoding them)?
    >
    > I want to do this because I have a page that has different querystring
    > variables passed into it depending on the content of the calling page.


    P.S. That would be querystring variables with names like

    test_page.asp?var1=3&var2=2&var6=8&var9=6

    How do I access var1, var2, var6 and var9 without hard coding them?
     
    Mike, Aug 17, 2005
    #2
    1. Advertising

  3. Mike wrote:
    > "Mike" <> wrote in message
    > news:%...
    >> Is it possible to loop round all querystring parameters in a web page
    >> (i.e. access them without hardcoding them)?
    >>
    >> I want to do this because I have a page that has different
    >> querystring variables passed into it depending on the content of the
    >> calling page.

    >
    > P.S. That would be querystring variables with names like
    >
    > test_page.asp?var1=3&var2=2&var6=8&var9=6
    >
    > How do I access var1, var2, var6 and var9 without hard coding them?


    The following works with all the Request collections (Form, ServerVariables,
    Querystring):

    dim key
    for each key in Request.Querystring
    Response.Write key & ": " & Request.Querystring(key) & "<BR>"
    next

    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Aug 17, 2005
    #3
  4. Mike

    Phill. W Guest

    "Mike" <> wrote in message
    news:%...
    > Is it possible to loop round all querystring parameters in a web page

    (i.e.
    > access them without hardcoding them)?


    Request.QueryString doesn't support a Contents property (like
    Session) so you'll probably have to pull the QueryString apart
    yourself, something like :

    sQS = Request.QueryString
    For Each eItem in Split( sQS, "&" )
    sName = Left( eItem, Instr( eItem & "=", "=" ) - 1 )
    Response.Write sName _
    & " = " & Request.QueryString( sName ) _
    & "<br>"
    Next

    Watch out; you may /still/ fall foul of URLEncode'd parameter names.

    HTH,
    Phill W.
     
    Phill. W, Aug 17, 2005
    #4
  5. Mike

    Phill. W Guest

    "Bob Barrows [MVP]" <> wrote in message
    news:%23dD%...
    > Mike wrote:
    > > "Mike" <> wrote in message
    > > news:%...
    > >> Is it possible to loop round all querystring parameters in a web page
    > >> (i.e. access them without hardcoding them)?

    .. . .
    > The following works with all the Request collections (Form,
    > ServerVariables, Querystring):
    >
    > dim key
    > for each key in Request.Querystring
    > Response.Write key & ": " & Request.Querystring(key) & "<BR>"
    > next


    Now how on Earth did I forget that???

    Regards,
    Phill W.
     
    Phill. W, Aug 17, 2005
    #5
  6. Mike

    Mike Guest

    "Bob Barrows [MVP]" <> wrote in message
    news:%23dD%...
    > Mike wrote:
    >> "Mike" <> wrote in message
    >> news:%...
    >>> Is it possible to loop round all querystring parameters in a web page
    >>> (i.e. access them without hardcoding them)?
    >>>
    >>> I want to do this because I have a page that has different
    >>> querystring variables passed into it depending on the content of the
    >>> calling page.

    >>
    >> P.S. That would be querystring variables with names like
    >>
    >> test_page.asp?var1=3&var2=2&var6=8&var9=6
    >>
    >> How do I access var1, var2, var6 and var9 without hard coding them?

    >
    > The following works with all the Request collections (Form,
    > ServerVariables, Querystring):
    >
    > dim key
    > for each key in Request.Querystring
    > Response.Write key & ": " & Request.Querystring(key) & "<BR>"
    > next
    >
    > HTH,
    > Bob Barrows


    Absolutely perfect, thanks.
     
    Mike, Aug 17, 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. Mehdi
    Replies:
    6
    Views:
    36,142
    sloan
    Apr 6, 2006
  2. Replies:
    0
    Views:
    1,102
  3. OliverMarchand

    Float.round - should it be round-to-even

    OliverMarchand, Apr 12, 2006, in forum: Ruby
    Replies:
    2
    Views:
    226
    OliverMarchand
    Apr 12, 2006
  4. cerr

    reading file round and round

    cerr, Mar 19, 2010, in forum: Perl Misc
    Replies:
    6
    Views:
    185
    Peter J. Holzer
    Mar 20, 2010
  5. Isaac Won
    Replies:
    9
    Views:
    390
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page