Visual Basic Concepts

Retrieving Information from an HTML Form

See Also

You can use the Request object to retrieve the information a user enters on an HTML form. Submitting a form can fire an event within your webclass, if you have connected the FORM ACTION tag attribute to an event; if so, you can use this event to gather and manipulate information. You use the Request object's Form collection to retrieve named fields from the form and set their value equal to variables in the webclass. For example, the following code shows how you would retrieve information from a book request form in an order entry application:

Private Sub BookList_Search()
   ' declare variables for form information
   Private sTitle as String
   Private sAuthor as String
   Private sPublisher as String

   ' retrieve form arguments and assign to variables
   sTitle = Request.Form("title")
   sAuthor = Request.Form("author")
   sPublisher = Request.Form("publisher")

   ' further code here to process this information,
   'open the database, find the book, and return it.
End Sub

When you add a template that contains a form to a webclass, you might notice that the form elements, such as buttons and text areas, do not appear in the Detail panel and event candidates. You can have the webclass respond to events that occur on these form elements by connecting the parent Form for the elements to an event. Then write code for the parent form that uses the Request object's Form collection to determine which element was selected.

For More Information   See "The Object Model for IIS Applications" for more information on using ASP objects in your webclass code.