Read Post Data Submitted to ASP.NET Form

Read Post Data submitted to ASP.Net Form

Read the Request.Form NameValueCollection and process your logic accordingly:

NameValueCollection nvc = Request.Form;
string userName, password;
if (!string.IsNullOrEmpty(nvc["txtUserName"]))
{
userName = nvc["txtUserName"];
}

if (!string.IsNullOrEmpty(nvc["txtPassword"]))
{
password = nvc["txtPassword"];
}

//Process login
CheckLogin(userName, password);

... where "txtUserName" and "txtPassword" are the Names of the controls on the posting page.

How can I get post data for asp.net c#

Try this

string[] keys = Request.Form.AllKeys;
var value = "";
for (int i= 0; i < keys.Length; i++)
{
// here you get the name eg test[0].quantity
// keys[i];
// to get the value you use
value = Request.Form[keys[i]];
}

How to get POST and GET data from a FORM in ASP.NET

Get variables are stored in the query string:

String getText1 = Page.Request.QueryString["text1"];

Post variables are stored in the form:

String postText1 = Page.Request.Form["text1"];

If you want to know more about the difference between Get and Post variables, I'd suggest having a read of this question: When do you use POST and when do you use GET?

Getting values posted by a form on target page ASP.NET

Request.QueryString is used to access parameters passed using GET; to access parameters passed via POST you should use Request.Form:

public partial class formtarget : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String name = Request.Form["namebox"];
String age = Request.Form["agebox"];

namelab.Text = name;
agelab.Text = age;
}
}

Retrieve all posted values in ASP.NET

The Request.Form property returns a NameValueCollection you can iterate over:

foreach (string name in Request.Form.AllKeys) {
string value = Request.Form[name];
// Do something with (name, value).
}

How to Get the HTTP Post data in C#?

This code will list out all the form variables that are being sent in a POST. This way you can see if you have the proper names of the post values.

string[] keys = Request.Form.AllKeys;
for (int i= 0; i < keys.Length; i++)
{
Response.Write(keys[i] + ": " + Request.Form[keys[i]] + "<br>");
}

Get the post method payload in asp.net webforms

It was issue of SAMLResponse is empty when request reach to login page. By using Request.Form["SAMLResponse"] in global.asax page I am able to get the value. Thanks

get names and values of a form post

Loop over all the items in Request.Form.

-- Edit:

Like so:

foreach(string key in Request.Form){
Response.Write(key + "=" + Request.Form[key]);
}

Get POST Values in ASP.NET using NameValueCollection

I think you have to use Page.PreviousPage Property
You can get the dropdown value as

if (Page.PreviousPage != null)
{
DropDownList ddl= (DropDownList)Page.PreviousPage.FindControl("cmboOptions$cmboOptions_TextBox");
// You have an AjaxToolkit Combo Box, so you must cast it as
AjaxToolKit.ComboBox ddl= (AjaxToolKit.ComboBox )Page.PreviousPage.FindControl("cmboOptions");
if (ddl != null)
{
// do your work
}
}

Read more on msdn about Cross Page Posting in Asp.net

Updated Answer:
To check the Steve code I created a page with a dropdownlist and a button to do postback ( Currently I don't have ajaxtoolkit so I'm using dropdownlist )

<asp:DropDownList ID="ddl" runat="server"  >
<asp:ListItem></asp:ListItem>
<asp:ListItem Text="Option 1" Value="opt1" > </asp:ListItem>
<asp:ListItem Text="Option 2" Value="opt2" ></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
PostBackUrl="~/Default4.aspx" />
// This code was written on Default5.aspx

// Default4.aspx code behind
protected void Page_Load(object sender, EventArgs e)
{
NameValueCollection nvc = Request.Form;
string val = Request.Form["ddl"];
string val2 = nvc["ddl"];
// Both above statement returns the required result
}

So, i think the problem is with the Ajax Combo box.( if you are not doing any mistake )

Updated Answer:
The problem is that the ID of Ajax Combo box control is changed when we post the page. In the Next page we can get the ID of ajax combox box as

For Pages Without Master Pages:
If you are using an aspx page without master page then you can get the ID of ajax combo box as

     //Ajax Combo Box ID format
ComboBoxID + "$TextBox"
// so If I have a combo box with ID ComboBox1 it becomes
ComboBox1$TextBox
so we will get the value as
string comboBoxvalue = Request.Form["ComboBox1$TextBox"];
or
NameValueCollection nvc = Request.Form;
string cmbvalue = nvc["ComboBox1$TextBox"];

For Pages using MasterPages:

    //Ajax Combo Box ID format
"ctl00$" + ContentPlaceHolderID +"$" + ComboBoxID + "$TextBox"
//I have a combox Box with ID ComboBox1 and ContentPlaceHolderID ContentPlaceHolder1
so AjaxComboBox ID becomes ctl00$ContentPlaceHolder1$ComboBox1$TextBox

string cmbvalue = nvc["ctl00$ContentPlaceHolder1$ComboBox1$TextBox"];

// In your case
// ComboxBox ID is cmboOptions and ContentPlaceHolderID is MainContent
// so your ID becomes
ctl00$MainContent$cmboOptions$TextBox
// so you will get the data as
string cmbvalue = nvc[" ctl00$MainContent$cmboOptions$TextBox"];


Related Topics



Leave a reply



Submit