2016-05-15 63 views
0

我在用戶控件中有2個單選按鈕,並且控件已註冊到該頁面。當我單擊單選按鈕時,事件(CheckChanged)不會觸發。單選按鈕檢查更改甚至沒有觸發

<asp:View ID="viewfirst" runat="server"> 
        <asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Always"> 
         <ContentTemplate> 

          <asp:RadioButton ID="radio1" Text="Yes" Enabled="true" runat="server" /> 
          <asp:RadioButton ID="radio2" Text="No" Enabled="true" runat="server" /> 
         </ContentTemplate> 
        </asp:UpdatePanel> 
       </asp:View> 

Below is code in behind file of the control. 


Protected Sub radio1_CheckedChanged(sender As Object, e As EventArgs) Handles radio1.CheckedChanged 
    // 
    // 
End Sub 

看起來一切看起來不錯,但有些事情是錯誤的。你可以讓我知道。

+0

在這件事情中沒有什麼,你會怎麼知道它是否會燃燒? – OneFineDay

+0

將'autopostback = true'添加到單選按鈕 – Sandeep

回答

2

設置的AutoPostBack =真的複選框 - 這將觸發事件

的UpdateMode =條件ChildrenAsTriggers =假的UpdatePanel的 - 所以,當你觸發複選框,也不會觸發完全回發

0

你必須每個單選按鈕的事件處理程序設置爲OnCheckChanged,並把m在同一個RadioGroup(GroupName),所以他們不一起射擊。記得爲每個單選按鈕設置AutoPostBack = true。設置只有一個 radioButton爲checked = true。我可以看到你的代碼已經被檢查。事情是這樣的......

aspx頁面:

<asp:RadioButton id="radioButton1" runat="server" GroupName="btnGrp" Text="Button 1" AutoPostBack="true" Checked="true" OnCheckedChanged="radioButton1_CheckedChanged"></asp:RadioButton> 

<asp:RadioButton id="radioButton2" runat="server" GroupName="btnGrp" Text="Button 2" AutoPostBack="true" OnCheckedChanged="radioButton2_CheckedChanged"></asp:RadioButton> 

代碼隱藏(aspx.cs)頁:

protected void radioButton1_CheckedChanged(object sender, EventArgs e) 
    { 
     // Your code here 
    } 

protected void radioButton2_CheckedChanged(object sender, EventArgs e) 
    { 
     // Your code here 
    } 

希望這有助於!

相關問題