gpt4 book ai didi

asp.net - 如何在asp中提交表单并获取其值

转载 作者:行者123 更新时间:2023-12-05 00:50:43 27 4
gpt4 key购买 nike

我有一个带有单选按钮的表单和一个仅重新加载页面而不提交表单数据的提交按钮...我应该在表单操作或方法中做什么,以便我可以获得这些单选按钮值

<form id="form2" name="form2" method="post" action="" runat="server">

<br />

<asp:Button ID="Button1" runat="server" Text="Button" />
</form>

最佳答案

您的代码似乎没有任何单选按钮控件...

显示不同选项的示例:

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>

代码:

//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;

}

关于asp.net - 如何在asp中提交表单并获取其值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364315/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com