I have three radio buttons on a form – A, B, C. Each of these selections populates a dropdown list with data specific to the option. When the form loads, I set option A to be checked (as the default).
When I select buttons B or C, the AsyncPostBack triggers fine and the dropdown is populated. BUT, subsequently selecting A from either B or C does not trigger the event.
I suspect that because A was checked when the form loaded, the browser is not seeing any "change" to raise the event.
So what can be done to enable the default A button recognise it is being changed from B or C in order to raise the postback?
I have tried both setting the checked state of button A in code on inital loading of the page only (ie IsPostBack is False) and alternatively setting the checked attribute of the radiobutton in the html, with the same results. If I don't default the radio button the functionality works as expected, except I don't have the radio button and dropdown list defaulted when the page first loads.
<asp:RadioButton ID="radBook" runat="server" AutoPostBack="true" GroupName="grpArticleType" Text="Book" /> <asp:RadioButton ID="radCD" runat="server" AutoPostBack="true" GroupName="grpArticleType" Text="CD" /> <asp:RadioButton ID="radDVD" runat="server" AutoPostBack="true" GroupName="grpArticleType" Text="DVD" /> <asp:UpdatePanel ID="pnlTasks" runat="server" UpdateMode="Conditional" RenderMode="Inline"> <ContentTemplate> <asp:DropDownList ID="dropShippingSize" runat="server" CssClass="dropdownMandatory"></asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="radBook" /> <asp:AsyncPostBackTrigger ControlID="radCD" /> <asp:AsyncPostBackTrigger ControlID="radDVD" /> </Triggers> </asp:UpdatePanel>
The code behind…
Sub Page_Load If Not Me.IsPostBack Then radBook.Checked = True End If End Sub Private Sub rad_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles radBook.CheckedChanged, radCD.CheckedChanged, radDVD.CheckedChanged zLoadShippingSizeDropdown() End Sub
I had the same problem and looked for an answer for hours. This seems to have nothing to do with ViewState or anything similar, but with some kind of incompatibility of using a pre-checked RadioButton as trigger for an Async PostBack. The work around I found is amazingly easy and worked right away; instead of using the
checked=trueon the mark-up or
myRadioButton.Checkedon the server side, I did the following:
Not setting the attribute on Mark-up and add this on the
I hope this helps and saves some people hours of hair pulling :)