[英]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.