How To Create a Reentrant ASP Page (260529)



The information in this article applies to:

  • Microsoft Active Server Pages
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Server 5.0
  • Microsoft Visual Basic, Scripting Edition 4.0
  • Microsoft Visual Basic, Scripting Edition 5.0

This article was previously published under Q260529

SUMMARY

It is possible to create a single ASP page that can both display an HTML form to gather user input, and process the values that are submitted in the form. This can be implemented by setting the ACTION parameter of the FORM tag to the same ASP page that hosts it, and writing server-side script to conditionally display the form or process the input that is submitted by using the form. Such an ASP page is called a Reentrant ASP page.

HTML forms are commonly used in Internet and intranet applications to gather user input and feedback. The information entered or selected in the HTML intrinsic controls on the form are usually submitted to an ASP page on the Web server. The ASP page processes the user inputs and generates a Response HTML page to be sent back to the client browser.

This article addresses a scripting technique that can be used to create a Reentrant ASP page.

MORE INFORMATION

Steps to Create a Reentrant ASP Page

The code sample in this section uses VBScript as the server-side scripting language. The following steps create a simple reentrant ASP page:
  1. Open a new ASP file in your favorite Web page editor.
  2. Save the new file as Reentrant.asp in a virtual folder on your Web server.
  3. Cut and paste the following code into the file:
    <%@Language=VBScript%>
    <%
    If Trim(Request.Form("txtName")) <> "" Then
      Response.Write "You Entered the Following Details : " & "<HR>"
      Response.Write "Name : " & Request.Form("txtName") & "<BR>"
      Response.Write "Email : " & Request.Form("txtEmail") & "<BR>"
      Response.Write "<HR>"
      Response.End
    End If
    %>
    
    <HTML>
    <BODY>
    
    <FORM METHOD="POST" ACTION="Reentrant.asp">
    
    Enter Your Name : <BR>
    <INPUT TYPE=text NAME=txtName> <BR><BR>
    
    Enter your E-mail address : <BR>
    <INPUT TYPE=text NAME=txtEmail> <BR><BR>
    
    <INPUT TYPE=submit Value="Submit">
    
    </FORM>
    
    </BODY>
    </HTML>
    						
    The HTML tags in the Reentrant.asp file define an HTML form that contains two intrinsic text box controls to accept a visitor's name and e-mail address. The ACTION parameter of the FORM tag is set to point to the same ASP page that contains it; this sets up a Reentrant page.

    When a visitor submits the form after entering his or her name and e-mail address, the form is posted back to Reentrant.asp. In this example, the txtName element is used to determine whether the user input form is to be displayed, or if the Response HTML page is to be generated by the ASP in response to the form submission.

    It is assumed that a value is specified in the txtName element when the form is submitted for processing. The If condition in the script checks to see if an input is provided for the txtName element. The enclosed script that generates the Response HTML page acknowledging the input received is executed when the user submits the form after entering a value in the txtName text box control on the HTML form.

    The Response.End statement is required to terminate the processing of the script and to send the buffered output to the client browser.
  4. Open the ASP page in your Web browser by typing in its URL. Note that the HTML form is displayed when the page opens in the browser. Enter your name and e-mail address in the text boxes on the form, and then click Submit. Note that the same ASP page now generates a Response page to acknowledge your inputs.

Modification Type:MinorLast Reviewed:6/29/2004
Keywords:kbhowto KB260529