简体   繁体   English

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

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

I have 2 RadioButtonLists and I want only one option to be selected, fi if you select an option in List 1 the selection in List 2 should be cleared. 我有2个RadioButtonLists,我只希望选择一个选项,如果您在列表1中选择一个选项,则应清除列表2中的选择。

AutoPostBack and EnableViewState is set to true, but still the Method never fires. AutoPostBack和EnableViewState设置为true,但是该方法永远不会触发。 I have also checked if the Index actually changes, it does. 我还检查了索引是否确实发生了变化。 I think that the PostBack just doesn't occur, but I don'T know why. 我认为PostBack不会发生,但我不知道为什么。

I'm thankful for any help. 感谢您的帮助。

ascx: 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>

Code Behind: 背后的代码:

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

change the control to RadioButton and add GroupName to them will do the trick: 将控件更改为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>

try to use just one radibuttonlist and options. 尝试仅使用一个单选按钮列表和选项。

 <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.

相关问题 RadioButtonList:OnSelectedIndexChanged 未触发 - RadioButtonList: OnSelectedIndexChanged not firing 尽管autopostback为true,Asp.net OnSelectedIndexChanged事件未触发 - Asp.net OnSelectedIndexChanged event not firing despite autopostback being true DropDownList OnSelectedIndexChanged未触发(AutoPostBack为“ true”,未发现其他问题) - DropDownList OnSelectedIndexChanged not firing (AutoPostBack is “true”, no other issues found) RadioButtonList OnSelectedIndexChanged仅触发一次 - RadioButtonList OnSelectedIndexChanged Only firing ONCE 尽管autopostback设置为true,RadioButtonList仍未发布 - RadioButtonList not posting back despite autopostback being set to true DropDownList 事件未在 AutoPostBack 设置为 true 时触发 - DropDownList event not firing with AutoPostBack set to true RadioButtonList OnSelectedIndexChanged - RadioButtonList OnSelectedIndexChanged 当RadioButtonList选择asp.net C#时,SelectedIndexChanged无法正常工作? autopostback还设置为true吗? - SelectedIndexChanged not working while RadioButtonList selected asp.net c#? autopostback also set to true? DropDownList SelectedIndexChanged不触发(AutoPostBack =“ true”) - DropDownList SelectedIndexChanged not firing (AutoPostBack=“true”) DDL的SelectedIndexchanged没有触发(AutoPostBack =“ true”) - Selectedindexchanged for DDL is not firing (AutoPostBack = “true”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM