Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

9.1. Gathering Data from the User

Literally every web site on the Internet has to deal with input from the user. Generally, this input can be sent to the web server with two different techniques, GET and POST. In Chapter 4 you briefly saw the difference between these two methods and saw that GET data is appended to the actual address of the page being requested whereas with the POST method the data is sent in the body of the request for the page.

With the GET method, data is added to the query string of a page. You can retrieve it using the QueryString property of the Request object as discussed in Chapter 7. Imagine you are requesting the following page:

http://www.PlanetWrox.com/Reviews/ViewDetails.aspx?id=34&catId=3

With this example, the query string is id=34&catId=3. The question mark is used to separate the query string from the rest of the address. To access individual items in the query string, you can use the Get method of the QueryString collection:

VB.NET

Dim id As Integer = Convert.ToInt32(Request.QueryString.Get("id"))      ' id is now 34
Dim catId As Integer = Convert.ToInt32(Request.QueryString.Get("catId")) ' catId is now 3

C#

int id = Convert.ToInt32(Request.QueryString.Get("id"));                 // id is now 34
int catId = Convert.ToInt32(Request.QueryString.Get("catId"));           // catId is now 3

The POST method on the other hand gets its data from a form with controls that have been submitted to the server. Imagine you have a form with two controls: a TextBox called txtAge to hold the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book