我面臨的問題是第一個單選按鈕的選中更改的事件未觸發。我啓用ViewState
但仍然存在問題。請看下面的代碼:ASP.NET單選按鈕檢查更改的事件不會觸發第一個單選按鈕
<span class="pull-right text-right">
<label class="inline radio">
<asp:RadioButton runat="server" ID="rdoViewAll" CausesValidation="false" GroupName="Filter" Text="View All" AutoPostBack="true" EnableViewState="true" Checked="true" />
</label>
<label class="inline radio">
<asp:RadioButton runat="server" ID="rdoViewCurrent" CausesValidation="false" GroupName="Filter" Text="View Current" AutoPostBack="true" />
</label>
<label class="inline radio">
<asp:RadioButton runat="server" ID="rdoViewFuture" CausesValidation="false" GroupName="Filter" Text="View Future" AutoPostBack="true" />
</label>
</span>
而且我對Page_Init
如下設置檢查更改事件:
public void Page_Init(object sender, EventArgs e)
{
this.rdoViewAll.CheckedChanged += (s, a) =>
{
RebindTerms();
};
this.rdoViewFuture.CheckedChanged += (s, a) =>
{
RebindTerms();
};
this.rdoViewCurrent.CheckedChanged += (s, a) =>
{
RebindTerms();
};
}
有一件事我注意到的是,當我刪除第一個單選按鈕CheckedChanged
的Checked="true"
財產事件成功啓動。但是,我需要在頁面加載時默認檢查第一個單選按鈕。
我相信你已經知道你不能不選中另一個組中的RadioButton。因此,CheckedChanged事件只會觸發剩下的取消選中RadioButton,而不是已經檢查過的RadioButton,所以在你的情況下,rdoViewAll是你的默認值,事件只會觸發rdoViewFuture和rdoViewCurrent。 –
我建議你改用Click事件。 –
@ Dr.Stitch - RadioButton沒有可以在代碼隱藏中處理的Click事件。 – ConnorsFan