The QueryString Collection

The QueryString collection creates a parsed version of the QUERY_STRING server variable. This information is the part of an HTTP request that comes after the question mark. This collection provides the same easy access to the Request variables that the Form collection provides to Form variables.

The syntax for using the QueryString collection is

Request.QueryString(variable)[(index)|.Count] 

The most common way to extract the contents of an HTTP request is to use the Form collection of the Request object. But you can get an HTTP request that is not from a form. In that case, you use the QueryString collection to pull the individual variables from the query string.

Each variable in a query string has a name associated with it. The following example has two variables, Name and Age:

http://www.hypothetical.com/nameinfo.asp?name=fred&age=22 

To access the Name and Age variables, you use the following syntax:

TheName = Request.QueryString("name")      ' value is "fred" TheAge = Request.QueryString("age")     ' value is 22 

As with the Form collection, the QueryString collection can contain the same variable name more than once. If two values are sent with the same name, you can access the different values by using an index. In the following example, QueryString has two values for the name variable:

http://www.old.com/nameinfo.asp?name=Tony+Orlando&name=Dawn&age=22 

You can get the values by using a numeric index after specifying the variable:

Name1 = Request.QueryString("name")(1) ' Value is "Tony Orlando" Name2 = Request.QueryString("name")(2) ' Value is "Dawn" 

You can also determine the number of values in the name variable by calling the following:

Request.QueryString("name").Count 

To print out all the values in the name variable, you use a looping structure, as follows:

<%     For I = 1 To Request.QueryString("name").Count              Response.Write Request.QueryString("name")(I) & "<BR>"     Next %> 



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net