2011-04-04 70 views
1

我有一個RadioButtonList與一些固定的元素和默認選中。如果我取消選中javascript,回發時SelectedIndexChanged事件不會被觸發。Uncheched RadioButtonList不會觸發SelectedIndexChanged

我期望SelectedIndexChanged被調用,因爲索引更改爲-1。

這是Asp.Net代碼

<asp:RadioButtonList ClientIDMode="Static" ID="RadioButtonList1" runat="server" 
    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"> 
    <asp:ListItem Value="1" Selected="True"></asp:ListItem> 
    <asp:ListItem Value="2"></asp:ListItem> 
</asp:RadioButtonList> 

和jQuery代碼

$('#RadioButtonList1 :radio:visible').attr('checked', false); 

據我所知,數據收集的從提交表單的階段是由處理IPostBackDataHandler.LoadPostData方法。

我派生的類從RadioButtonList的驗證時的LoadPostData被調用,我注意到,當被選擇的單選按鈕的非該方法不被調用和相同的用於SelectedIndexChanged事件。

看來,如果RadioButtonList的關鍵字不存在於Page.Request.Form.Keys數組中,則不會調用LoadPostData。

任何幫助表示讚賞。

回答

0

嘗試設置AutoPostBack="true"

實施例:

<asp:RadioButtonList ClientIDMode="Static" ID="RadioButtonList1" runat="server" 
    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true"> 
    <asp:ListItem Value="1" Selected="True"></asp:ListItem> 
    <asp:ListItem Value="2"></asp:ListItem> 
</asp:RadioButtonList> 

根據MSDN的文檔:

獲取或設置指示 的值的回發到服務器 是否自動產生當用戶 更改列表選擇。 (從ListControl繼承 )。

+0

好的,我試過了,但結果仍然是一樣的。 Pheraps問題不是回發發生的方式,而是它在服務器端處理的方式。 – 2011-04-05 11:27:22

+0

您提出的解決方案的問題是,當使用JavaScript取消選擇單選按鈕時,回發不會發生。 – 2011-04-06 09:34:18

相關問題