Name
Form
Synopsis
NameValueCollection = Request.Form
The
Form collection returns an instance
of the NameValueCollection
class containing all
form fields passed along with an HTTP POST request. This collection
will contain data only when the Content-Type of the HTTP request is
either application/x-www-form-urlencoded
or
multipart/form-data
.
The Form collection is one of two ways to retrieve data, depending on
the HTTP method used to submit the data. The Form collection
retrieves data submitted by an HTML form whose
method
attribute is set to
POST
, while the QueryString collection (covered
later in this section) retrieves values submitted by HTML forms whose
method
attribute is set to GET
.
Parameters
-
NameValueCollection
An Object variable of type NameValueCollection.
Example
The example demonstrates how ASP.NET allows a single page to be used
to submit values via HTTP POST and retrieve and display the values to
the user. The example uses the IsPostBack property of the
Page
class to determine whether the request is a
result of the form being submitted. If the request is not a postback,
the form fields are displayed to allow the user to enter values. If
the request is a postback, the page retrieves the Form collection and
displays the name and value of each field in the browser.
Sub Page_Load( ) If IsPostBack Then Form1.Visible = False If Request.HttpMethod = "POST" Then Dim Counter1 As Integer Dim Keys( ) As String Dim FormElements As NameValueCollection ' Get Form keys/elements FormElements=Request.Form ...
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.