tags:

views:

127

answers:

2

I am wondering how I can get the post data in a collection format? Say if I have a form and one textbox named firstname, normally i type

var fn = txtFirstName.Text;

to get the data from that textbox. but I am wondering when i click on submit data to post the form how i can get the collection of raw post data?

thank you.

I want to get the post data instead of get.

+4  A: 

You can access the Request object directly. It is a collection of all the form elements. You can loop through them or access them by name as follows:

Request["txtFirstName"]

EDIT: If however, there's a querystring variable with the same name, that will be used first. In that case, Request.Form["txtFirstName"] should be used to instead.

Jose Basilio
thank you very much.
Jeffrey C
+3  A: 

Request["txtFirstName"] will actually give you the URL argument, like:

http://www.example.com/Page.aspx?txtFirstName=value

If you want the value that is posted to the page from an input with the name txtFirstName you want Request.Form["txtFirstName"]

JerSchneid
@JerSchneid - both Request["txtFirstName"] and Request.Form["txtFirstName"] bring back the same result provided there isn't a querystring with the same name.
Jose Basilio