System.Web Namespace HttpRequest Class
Returns a collection of form variables.
Script |
[ NameValueCollection variable = ] Request.Form |
The property is read only with no default value.
Request.Form returns a collection of name/value
pairs representing the elements of a client form submitted via the POST method. This collection is populated when the HTTP request Content-Type is either
- multipart/form-data, or
- application/x-www-form-urlencoded.
To obtain the value of a single form input element, use
Request.Form[ "controlName" ]
Request.Form ( "controlName" ) |
|
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.Form ) {
Response.Write ( Request.Form[ var ] );
}
dim var as string
for each var in Request.Form
Response.Write ( Request.Form ( var ) )
next |
|
C# |
VB |
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 POST method.
<table class="data" width="90%">
<tr>
<th>Name</th>
<th>Value</th></tr>
<% string val;
foreach ( string name in Request.Form ) {
If ( Request.Form[ name ] != "" ) val = Request.Form[ name ];
else val = " "; %>
<tr>
<td><%= name %></td>
<td><%= val %></td></tr>
<% } %>
</table>
Show me
HttpRequest Members Request.QueryString