To transfer data from the client to the server, forms are often used, which group several controls together.
In the example below, the form contains two fields — Name and E-Mail — and two buttons — Submit and Reset.
- Clicking the Submit button initiates the execution of the ASP file specified in the action attribute of the <form> tag (in this case, Answer.asp).
- The form property of the server-side Request object passes the values of the input elements within the form to this file.
- The identification of tags is performed using the values of their name attributes.
After filling out the form, the user clicks Submit, which sends the data to the server and processes it with the program Answer.asp, confirming that the data has been received.
Clicking the Reset button clears the form values, restoring their default values.
Steps to Run This Example
- In Notepad, type the following codeand save the file as ask.htm.
Transferring data from client to server. File ask.htm
<html> <body> <h1>Enter Your Data</h1> <form id="frmName" method="post" action="http://localhost/answer.asp"> Name: <input type="text" name="txtName"> <br> E-Mail: <input type="text" name="txtEMail"> <br> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> </body> </html>
- Then type the following code in Notepad and save the file as answer.asp.
Transferring data from client to server. File answer.asp
<%@ Language=VBScript %>
<html>
<body>
<%
Response.Write "<H2>Received Data</H2>"
Response.Write "Name: " & Request.Form("txtName")
Response.Write "<BR>"
Response.Write "E-Mail: " & Request.Form("txtEMail")
%>
</body>
</html>
- Place the created files in the directory C:\Inetpub\wwwroot on your computer.
- Launch the file iisstart.htm, located in the same directory, and in the browser’s address bar enter:
http://localhost/ask.htm
- Click the Submit button in the browser window and check the ASP request execution. Also, test the Reset button.
Our Results
- Forms are the main way to transfer data from the client to the server.
- The ASP Request.Form collection is used to retrieve form data.
- The Response.Write method confirms or processes the submitted data.