asp.net.ph

Request.QueryString Property

System.Web Namespace   HttpRequest Class


Returns the collection of HTTP query string variables.

Syntax


Script [ NameValueCollection variable = ] Request.QueryString

Property Value


variable Returns a NameValueCollection containing the collection of query string variables sent by the client.

The property is read only with no default value.

Remarks

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" ]
  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 ] );
}
  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.

Example

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 = "&nbsp;"; %>
<tr>
  <td><%= name %></td>
  <td><%= val %></td></tr>
<% } %>
</table>

 Show me 

See Also

HttpRequest Members   Request.Form Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph