System.Web Namespace HttpRequest Class
Returns the collection of HTTP query string variables.
Script |
[ NameValueCollection variable = ] Request.QueryString |
variable |
Returns a NameValueCollection containing the collection of query string variables sent by the client. |
The property is read only with no default value.
Request.QueryString returns a collection of name/value
pairs representing the elements of a client form submitted via the GET method. The HTTP query string is specified by the values following the question mark [ ? ] in the request URI.
To obtain the value of a single form input element, use
Request.QueryString[ "variableName" ]
Request.QueryString ( "variableName" ) |
|
C# |
VB |
To obtain the name and value pair of each form input element, you can loop thru the collection using a simple foreach statement.
foreach ( string var in Request.QueryString ) {
Response.Write ( Request.QueryString[ var ] );
}
dim var as string
for each var in Request.QueryString
Response.Write ( Request.QueryString ( var ) )
next |
|
C# |
VB |
While query strings are automatically generated by sending a form using GET, several different methods can also generate a query string. For example, the anchor tag
<a href="details.aspx?id=123">show details</a>
generates a variable named id
with the value of 123
. Query strings can also be generated by directly typing a query into the address box of the browser.
The following example [ C# ] shows how you can dynamically retrieve ( and display into an HTML table ) the name and value pair of each form input element passed from a client via a GET method.
<table class="data" width="90%">
<tr>
<th>Name</th>
<th>Value</th></tr>
<% string val;
foreach ( string name in Request.QueryString ) {
If ( Request.QueryString[ name ] != "" ) val = Request.QueryString[ name ];
else val = " "; %>
<tr>
<td><%= name %></td>
<td><%= val %></td></tr>
<% } %>
</table>
Show me
HttpRequest Members Request.Form