3

Im posting some data from another page using a form with the method post. What i would like to know is: Whats the best way to get the values. Going by eacn name in the form as

Request["name"]

Or is there any way to get a collection of the data and itterate through it? Thanks

Johan
  • 35,120
  • 54
  • 178
  • 293

3 Answers3

4

You can write

foreach (string key in Request.Form)

You may also want if (Request.HttpMethod == "POST") or if (Request.Form.Count > 0)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
2

You can use Request.Form, where the Form property is a collection of the form values:

foreach (var key in myCol.AllKeys)
{
     Response.Write(Request.Form[key]);
}
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
0

Request.Form Is the collection of posted key/value pairs.

asawyer
  • 17,642
  • 8
  • 59
  • 87