我想弄清楚为什么这段代码没有触发单选按钮更改事件。
这是 2 个单选按钮的 ASP 页面代码
<asp:RadioButton ID="rdoButton1" GroupName="Group1" Text="Yes" Value="Yes" runat="server" OnCheckedChanged="Group1_CheckedChanged" />
<asp:RadioButton ID="rdoButton2" GroupName="Group1" Text="No" Value="No" runat="server" OnCheckedChanged="Group1_CheckedChanged" />
下面是代码:
protected void Group1_CheckedChanged(Object sender, EventArgs e)
{
if (rdoButton1.Checked) {
panel1.Visible = true;
}
if (rdoButton2.Checked) {
panel1.Visible = false;
}
}
最佳答案
您需要指定属性和值 AutoPostBack="true"
为了告诉 ASP.NET 更改 that 元素应该触发回发。它应该应用于您希望引起回发的每个单独的 RadioButton。
关于c# - ASP.NET 单选按钮更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095256/