繁体   English   中英

RadioButtonList设置为AutoPostBack = true,但仍不触发OnSelectedIndexChanged

[英]RadioButtonList set to AutoPostBack = true but still not firing OnSelectedIndexChanged

我有2个RadioButtonLists,我只希望选择一个选项,如果您在列表1中选择一个选项,则应清除列表2中的选择。

AutoPostBack和EnableViewState设置为true,但是该方法永远不会触发。 我还检查了索引是否确实发生了变化。 我认为PostBack不会发生,但我不知道为什么。

感谢您的帮助。

ASCX:

<asp:RadioButtonList ID="_listOne" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButtonList>
<asp:RadioButtonList ID="_listTwo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButtonList>

背后的代码:

protected void ListOneIndexChanged(object sender, EventArgs e)
{
    _listTwo.ClearSelection();
}
protected void ListTwoIndexChanged(object sender, EventArgs e)
{
    _listOne.ClearSelection();
}

将控件更改为RadioButton并向其中添加GroupName即可达到目的:

<asp:RadioButton ID="_listOne" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButton>
<asp:RadioButton ID="_listTwo" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButton>

尝试仅使用一个单选按钮列表和选项。

 <asp:RadioButtonList id="radiolist1" runat="server" OnSelectedIndexChanged="ListOneIndexChanged">

   <asp:ListItem selected="true">Item 1</asp:ListItem>
   <asp:ListItem>Item 2</asp:ListItem>
   <asp:ListItem>Item 3</asp:ListItem>
   <asp:ListItem>Item 4</asp:ListItem>
</asp:RadioButtonList>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM