Monday, November 10, 2008

Get method and request object to collect data

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
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

Eg,
string name = "";
name=Request.QueryString.get("name");

No comments: