Retrieving data from a POST method in ASP.NET Retrieving data from a POST method in ASP.NET asp.net asp.net

Retrieving data from a POST method in ASP.NET


The data from the request (content, inputs, files, querystring values) is all on this object HttpContext.Current.Request
To read the posted content

StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream);string requestFromPost = reader.ReadToEnd();

To navigate through the all inputs

foreach (string key in HttpContext.Current.Request.Form.AllKeys){   string value = HttpContext.Current.Request.Form[key];}


You can get a form value posted to a page using code similiar to this (C#) -

string formValue;if (!string.IsNullOrEmpty(Request.Form["txtFormValue"])){  formValue= Request.Form["txtFormValue"];}

or this (VB)

Dim formValue As StringIf Not String.IsNullOrEmpty(Request.Form("txtFormValue")) Then    formValue = Request.Form("txtFormValue")End If

Once you have the values you need you can then construct a SQL statement and and write the data to a database.


You need to examine (put a breakpoint on / Quick Watch) the Request object in the Page_Load method of your Test.aspx.cs file.