how to submit form in asp and get its values
asp.net, html
Solution
Your code doesn't seem to have any radiobutton controls...
Samples showing different options:
HTML
<form id="form1" runat="server">
<div>
<p>
Name:
<asp:TextBox ID="textbox1" runat="server" />
<br />
Coffee preference:
<asp:RadioButtonList ID="CoffeeSelections" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
<asp:ListItem>Latte</asp:ListItem>
<asp:ListItem>Americano</asp:ListItem>
<asp:ListItem>Capuccino</asp:ListItem>
<asp:ListItem>Espresso</asp:ListItem>
</asp:RadioButtonList>
<br />
</p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
<div>
<h1>
Results</h1>
<p>
<asp:Label runat="server" ID="labelResults"></asp:Label></p>
</div>
</form>
Code:
//You can inspect on Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Only inspect on submission
if (Page.IsPostBack)
{
if (!string.IsNullOrEmpty(CoffeeSelections.SelectedValue))
{
labelResults.Text = CoffeeSelections.SelectedValue + "<br />";
}
//you can also inspect request.form colletion
foreach (string item in Request.Form)
{
labelResults.Text += "<b>KEY</b> : " + item + " <b>VALUE</b> = " + Request.Form[item] + "<br />";
}
}
}
//You can also inspect on raised control events (e.g. button)
protected void Button1_Click(object sender, EventArgs e)
{
string _foo = CoffeeSelections.SelectedValue;
labelResults.Text += _foo;
}
Problem
I have a form with radio buttons in it and a submit button which reload page only and not submit form data...what should i do in form action or method so that i can get these radio button values ``` <form id="form2" name="form2" method="post" action="" runat="server"> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /> </form> ```