ASP.NET 4.0 Radio button checked changed event fires only once

后端 未结 1 1745
终归单人心
终归单人心 2021-01-19 08:39

I have two radio buttons both set as async triggers for an update panel and problem is that first time one is clicked the CheckedChanged event fires but then no matter which

相关标签:
1条回答
  • 2021-01-19 09:11

    Looking at the source (in the browser), ASP.NET is only generating a post back function __doPostBack for the RadioButton controls which can possibly postback.

    The first RadioButton control cannot postback (because it is already checked), and as such the __doPostBack is not generated.

    A work around is to add the two RadioButton controls to another UpdatePanel, setting the UpdateMode to Always. This will cause the RadioButtons to be updated (whenever they trigger the other UpdatePanel) adding the __doPostBack function to the deselected RadioButton.

    Example

    <asp:UpdatePanel ID="UpdatePanelCheckBoxes" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:RadioButton ID="rdoDeliveryBilling" runat="server" Checked="true" GroupName="DeliveryAddress" Text="Deliver to this address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />
            <asp:RadioButton ID="rdoDeliveryShipping" runat="server" GroupName="DeliveryAddress" Text="Deliver to a different address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />            
        </ContentTemplate>
    </asp:UpdatePanel>
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题