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
Parameter | Description |
variable | Specifies a string or numeric 1-based index of the parameter_name |
index | Specifies one of multiple values for a variable, or index of the parameters in the query string |
count | Specifies 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
Example | Results |
Request.QueryString | a=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").count | 4 |
Request.QueryString("a")(2) | 3 |
Request.QueryString.count | 2 |
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!
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