2016-05-15 64 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 
    } 

希望这有助于!

相关问题