HOW TO: Use a Generic Collection to Parse HTTP Form Data with ASP

This article has been archived. It is offered "as is" and will no longer be updated.
We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:
This step-by-step article describes how to parse form data easily when you use Microsoft Active Server Pages (ASP) by using a generic collection instead of by explicitly defining the ASP collection for GET or POST requests.

When you use ASP to process data that is entered on a Web page through a form, two different collections are used depending on which HTTP method is specified in the form declaration:
  • GET uses the Request.QueryString collection.
  • POST uses the Request.Form collection.
This article describes how to process form data regardless of which HTTP method is used on the form.

NOTE: You may receive an error message if you copy the examples directly from this article to Microsoft FrontPage. The angle brackets (< and >) may appear as escaped HTML code (< and >). To work around this behavior, paste the script in a blank Notepad document, and then copy it from Notepad before you paste it in FrontPage.

back to the top

Create the Sample Pages

The following steps describe how to create a sample HTML page with two Web forms (one that uses the GET method and one that uses the POST method), and how to create a sample ASP page that processes the form by using either method.
  1. Save the following HTML code as Getdata.htm in the root folder of an IIS Web site:
    <html><body>POST <form action="showdata.asp" method="POST"><input type="text" name="txtData"><input type="submit"></form><br>GET <form action="showdata.asp" method="GET"><input type="text" name="txtData"><input type="submit"></form></body><html>					
  2. Save the following ASP code as Showdata.asp in the root folder of an IIS Web site:
    <% @language="vbscript" %><html><body><%   ' Declare a variable for the generic collection.   Dim objRequest   ' Determine the HTTP method used.   If UCase(Request.ServerVariables("HTTP_METHOD")) = "GET" Then      ' Use the QUERYSTRING collection with GET requests      Set objRequest = Request.QueryString   Else      ' Use the FORM collection with POST requests.      Set objRequest = Request.Form   End If   ' Escape and output the form data.    Response.Write Server.HTMLEncode(objRequest("txtData"))   %></body><html>					
When you open Getdata.htm by using HTTP (that is, by using an address such as http://localhost/getdata.htm), you may use either form to view the form results.

back to the top
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
300104 HOW TO: Pass Form Data from One Page To Another by Using GET and POST in Active Server Pages
back to the top

Article ID: 254742 - Last Review: 01/11/2015 03:25:03 - Revision: 4.0

  • Microsoft Active Server Pages 4.0
  • kbnosurvey kbarchive kbhowto kbhowtomaster KB254742