Microsoft KB Archive/300104

= How To Pass Form Data from One Page To Another by Using GET and POST in Active Server Pages =

Article ID: 300104

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q300104





IN THIS TASK
SUMMARY
 * Using the POST Method
 * Using the GET Method

REFERENCES



SUMMARY
One of the most commonly performed actions in Active Server Pages (ASP) Web development is passing data from one page to another for processing. This article contains step-by-step examples to demonstrate how to do this. Two techniques are involved: one uses the POST method, and the other uses the GET method. Although there are deeper levels of complexity regarding these approaches that you may consider, this article just illustrates how to apply these ideas.

NOTE: In these samples, only the second pages in each sequence must be .asp pages, because only these pages actually contain server-side code for the demonstration. The initial pages can be either .htm or .asp pages.

back to the top

Using the POST Method
When you use the POST method, you send the values for the HTML controls in a form to the page that is specified in the action attribute. To do this, follow these steps:  Create a new .htm page and name it Gatherdata_post.htm. To do this in Visual InterDev version 6.0, right-click the project node in the Project Explorer, click Add, click HTML Page, type Gatherdata_post.htm as the name of the page, and then click Open.  Paste the following code in the new page:NOTE: You should clear out the default code that InterDev adds when you initially create the page before you paste this code in the page. Otherwise, you will have redundant tags.  First Name:  Last Name:     Save the page. To do this, click Save Gatherdata_post.htm on the File menu in the Visual InterDev IDE.  Create another page named Retrievedata_post.asp. Paste the following code in the page, and save the page: <%@ Language=VBScript %> <% Response.Write(&quot;First Name: &quot; & Request.Form(&quot;txtFirstName&quot;) & &quot; &quot;) Response.Write(&quot;Last Name: &quot; & Request.Form(&quot;txtLastName&quot;) & &quot; &quot;) %>

</li> Run Gatherdata_post.htm by right-clicking the page and selecting View in browser. Enter some values for the first and last names, and then click Submit. Note that the data that you entered in Getdata_post.htm has been sent through HTTP POST to the Retrievedata_post.asp page for retrieval using the Request.Form collection.</li></ol>

back to the top

Using the GET Method
When you use the GET method, you send the values for the HTML controls in a form to the page that is specified in the action attribute in a manner that is similar to the POST approach that was described previously. However, you will notice that the values are sent in the QueryString. One main issue to consider when you use GET instead of POST is that the values are visible in the URL.

To use the GET method, follow these steps: <ol> Create a new .htm page and name it Gatherdata_get.htm. To do this in Visual InterDev version 6.0, right-click the project node in the Project Explorer, click Add, click HTML Page, type Gatherdata_get.htm as the name of the page, and then click Open.</li>  Paste the following code in the new page:NOTE: You should clear out the default code that InterDev adds when you initially create the page before you paste this code in the page. Otherwise, you will have redundant tags.  First Name: <INPUT id=&quot;txtFirstName&quot; name=&quot;txtFirstName&quot; > Last Name: <INPUT id=&quot;txtLastName&quot; name=&quot;txtLastName&quot; > <INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1> </FORM> </li> Save the page. To do this, click Save Gatherdata_get.htm on the File menu in the Visual InterDev IDE.</li>  Create another page named Retrievedata_get.asp. Paste the following code in the page, and save the page: <%@ Language=VBScript %> <% Response.Write(&quot;First Name: &quot; & Request.QueryString(&quot;txtFirstName&quot;) & &quot; &quot;) Response.Write(&quot;Last Name: &quot; & Request.QueryString(&quot;txtLastName&quot;) & &quot; &quot;) %>                   </li> Run Gatherdata_get.htm by right-clicking the page and selecting View in browser. Enter some values for the first and last names, and then click Submit. Note that the data that is entered in Getdata_get.htm is sent through GET to the Retrievedata_get.asp page for retrieval using the Request.QueryString collection. As you have seen, the QueryString collection is where your data is made available to the retrieving ASP page when you use GET as the action for the sending page, and the Form collection is used to retrieve the data when you implement POST.</li></ol>

back to the top

<div class="references_section">