The manual Page
Version française
     Collection Request.QueryString  
[ index | glossary | news | downloads | links ]
 
  introduction to ASP
writting in ASP
ASP variables
the ASP 3.0 objects
the object Request
   .TotalBytes
   .ClientCertificate
   .Cookies
   .Form
   .QueryString
   .ServerVariables
   .BinaryRead
the object Response
   .Status
   .Cookies
   .AddHeader
   .AppendToLog
   .BinaryWrite
   .Clear
   .End
   .Flush
   .Redirect
   .Write
 
news
glossary
downloads
 
guest book
credits
contact
 
 
research
 
last update
25/02/2002
Valid HTML 4.0!
Valid CSS!
Hit-Parade
Measure your audience

Synopsis

Request.QueryString(Variable)[(Index)|.Count]

Read only

This collection is used to handle the query string the client used to make its request. The query string is the part of the URL that follows the possible question mark ("?"). For instance, the query string in the URL http://www.myserver.com/page.asp?var1=foo&var2=bar is var1=foo&var2=bar.

This collection is very useful for forms sent with the GET method, or simply to pass a variable to an ASP page.

Request.QueryString works as the other collection Request.Form: Variable is the only mandatory parameter, Index and Count are optional.

Use of the collection

Get the variables

To get the variables passed through the URL or the data of a form, we simply use their names:

If the URL is http://www.myserver.com/page.asp?var1=foo&var2=bar, the collection Request.QueryString will contains the element Request.QueryString("var1") (which is set to "foo") and the element Request.QueryString("var2") (which is set to "bar").

Such an URL is formed with this kind of form:

<FORM action="form.asp" method="get">
	<INPUT type="text" name="var1" value="foo">
	<INPUT type="text" name="var2" value="bar">
	<INPUT type="submit" value="envoyer">
</FORM>

In VBScript, like all collections, it is possible to iterate through Request.QueryString with a For Each ... Next loop:

For Each element In Request.QueryString
	Response.Write(element & " = " & Request.QueryString(element))
Next

Multiple-value variables

We meet such variables when we use multiple lists or checkbox areas in a form (actually, everytime we use the same name for several form elements). We handle these variables with this collection as we do with the collection Request.Form. Index is an integer starting from 1 and ending at Request.QueryString(...).Count:

Initial form:

<FORM action="form.asp" method="get">
	<SELECT name="list" size="10" multiple>
		<OPTION value="element_1">element 1</OPTION>
		<OPTION value="element_2">element 2</OPTION>
		...
	</SELECT>
	<INPUT type="submit" value="OK">
</FORM>

or:

<FORM action="form.asp" method="get">
	<INPUT type="checkbox" name="list" value="element_1"> element 1<BR>
	<INPUT type="checkbox" name="list" value="element_2"> element 2<BR>
	...
	<INPUT type="submit" value="OK">
</FORM>

form.asp :

<%
Response.Write(Request.QueryString("liste").Count & " elements:<BR>")
For i = 1 To Request.QueryString("list").Count
	Response.Write(Request.QueryString("list")(i) & "<BR>")
Next
%>

If we selected or checked the elements 1, 5 or 13, we get:

3 elements:
element_1
element_5
element_13

The URL the client built is then the following: form.asp?list=element_1&list=element_5&list=element_13.

Finally, we can notice that we can directly get the query string by directly using Request.QueryString:

Response.Write(Request.QueryString) would render var1=foo&var2=bar

printable format printable format



Copyright © 2000-2001 themanualpage.org - This site is submissive to the terms of the GNU GPL and FDL licences.