0

My radio buttons are not retaining their stylized setting on a ajax postback.

I have something like this inside a panel

<div id="radio-grou-fu" class="btn-group" data-toggle="buttons">
     <asp:RadioButton GroupName="Group1" ID="Radio1Yes" AutoPostBack="true" runat="server" Checked="False" CssClass="btn btn-fix btn-default" Text="Yes"></asp:RadioButton>
     <asp:RadioButton GroupName="Group1" ID="Radio1No" AutoPostBack="true" runat="server" Checked="True" CssClass="btn btn-fix btn-default " Text="No"></asp:RadioButton>

When clicking on a styled button it correctly applies the "active" class to the span to style it correctly. However when i perform a partial postback, even though the checked state of the radio is persisting the 'active' class is getting removed and not reapplied.

Do i need some sort of JS to manually check if its checked and then apply the correct active class?

DDulla
  • 659
  • 9
  • 20

1 Answers1

0

It sounds like the postback is replacing the DOM element with the .active class with a fresh instance of the same element. Since you added .active to the old DOM element with JavaScript, your newly rendered postback won't have that class.

You can run some JS after the postback that checks if the radio is checked and applies .active.

Here's a discussion of how to trigger your JS after the postback is completed: https://stackoverflow.com/a/4223963/1712751

Community
  • 1
  • 1
Benjamin
  • 1,060
  • 11
  • 16