SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Get method and request object to collect data in ASP

As we have seen in ASP form basics, there is an Request object to handle or receive data of a form in the action page ( page specified in form action attribute ). We will learn how to get data using request object and how the data is posted through query string in GET method.

In GET method data of the form is passed through query string in name and value pairs. The data is separated from the file name by question mark( ? ) and between each pare of name and value ampersand ( & ) symbol is used to separate. Here is the example how in the GET method data is transferred.

http://www.plus2net.com/file_name.asp?name=john&country=USA&age=10


You can see in the above query string the form data is kept after the file name and the question mark ( ? ) . Then name and value pairs are used and they are separated by ampersand ( & ). This is the way data is posted using URL or the address bar of the browser window.

Collecting data using Request object in ASP
Once the form is submitted data is available to the page indicated at the action attribute of the form. Here we have to use Request.QueryString to get the value of the data field. To get the name entered by the user in name field here is the code

Dim name
Name=Request.QueryString(name)

Here we declared name as a variable for in the present script and then used Request object to collect the data of the name field. Now name field data is available to the variable name. Same way other data can be collected by using query string.

Here is the code of a form

<form method=get action=my_file.asp>
Your Name<input type=text name=name><br>
Age (years)<input type=text name=age size=3>
<input type=submit value='Submit Data'>
</form>

Here is the asp code inside my_file.asp file to collect the query string data

Dim name,age
name=Request.QueryString("name")
age=Request.QueryString("age")
Response.Write ("Welcome " & name & " You are " & age & " Years Old")


We can get all the query string data displayed by using for each loop as they are stored as name value pairs. Here is the code. Note that we are not using any individual form component name to collect the data.

Dim var_get
For Each var_get in Request.Querystring
Response.Write var_get & " = " & Request.Querystring(var_get) & "<br>"
Next


Further readings
Form Get method to collect data in ASP script
Form Post method to collect data
Difference between GET and Post method of form submission
Different ways of passing variables with data between pages
Form handling in ASP
Collecting checked radio button value of a HTML form in ASP
Collecting checkbox button value of a HTML form in ASP
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.