Did you find this useful?
Socialize it today.


ASP QueryString Collection

Saturday, September 01, 2012

tags ASP

In this ASP tutorial, we will be taking a look at how to pass variables and their values to an ASP page using the QueryString Collection, and how to access them from the target page. While you may not be an expert using query string, you certainly have seen one used before in a URL. For example, you may have been on an Internet site looking up a product in an online catalog and saw that the URL looked something like "www.website.com/catalog.asp?products=books&category=computers". In this example, the variable, products with a value of books was being passed from one page to the next. The question mark in the URL indicates the start of the query string and the ampersand (&), symbol separates the variables, if more than one exits. We can use the QueryString collection to access the variable and values in the query string on the target page.


Syntax

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

Parameters

ParameterDescription
variableSpecifies a string or numeric 1-based index of the parameter_name
indexSpecifies one of multiple values for a variable, or index of the parameters in the query string
countSpecifies the number of multiple values for a variable or number of variables in the query string


Examples

Lets take a look at some specific examples on how to use the Request.QueryString collection to access the information contained within the query string. The example URL is as follows: http://www.website.com/page.asp?a=1&b=5&a=3&a=6&a=7


ExampleResults
Request.QueryStringa=1&b=5&a=3&a=6&a=7&b=4
Request.QueryString(2)5, 4
Request.QueryString("a")1, 3, 6, 7
Request.QueryString("a").count4
Request.QueryString("a")(2)3
Request.QueryString.count2


Once you understand how to access the variable or variables in a query string, the next step is to determine what to do with those values. You may use that information to log a person into an application, or look up product information stored in a database. Finally, after you have process the query string information, display the dynamic data back to the end user.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

ASP In A Nutshell Beginning ASP Databases Sams Teach Yourself Active Server Pages 3.0 in 21 Days