【问题标题】:Radio Button Check Changed even not firing单选按钮检查已更改,即使未触发
【发布时间】:2016-09-11 16:33:12
【问题描述】:

我在用户控件中有 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

看起来一切都很好,但有些地方出了问题。请告诉我。

【问题讨论】:

  • 那个事件什么都没有,你怎么知道它是否触发?
  • autopostback=true 添加到单选按钮

标签: asp.net vb.net checkbox radio-button


【解决方案1】:

为复选框设置 autopostback=true - 这将触发事件

UpdateMode=conditionalChildrenAsTriggers=false 用于 UpdatePanel - 所以当您触发复选框时,它不会触发完整的回发

【讨论】:

    【解决方案2】:

    您必须将每个单选按钮的事件处理程序设置为 OnCheckChanged 并将它们放在同一个 RadioGroup (GroupName) 中,这样它们就不会一起触发。请记住为每个单选按钮设置 AutoPostBack = true。将 only one 单选按钮设置为选中 = 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
        }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2016-10-10
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      • 2015-09-02
      • 2019-02-22
      • 1970-01-01
      • 2012-07-14
      • 2011-12-24
      相关资源
      最近更新 更多