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 radio button is clicked the event never fires again.
Markup:
<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" />
<asp:UpdatePanel ID="panDeliveryAddress" runat="server">
<ContentTemplate>
...delivery details form controls and validators goes here...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoDeliveryBilling" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="rdoDeliveryShipping" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
Code:
protected void rdoDelivery_CheckedChanged(object sender, EventArgs e)
{
...only code that enables/disables the delivery form controls and validators goes here...
}
I have set a breakpoint inside rdoDelivery_CheckedChanged and it only hits the first time.
Any ideas?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With