tags:

views:

1079

answers:

3

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.


The html...

<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
A: 

I'm guessing you need to need to check if the page is a postback in your load event:

protected void Form_Load(object sender, EventArgs e) 
{
    if (!Page.IsPostback) 
    {
        // Set radiobutton A...
    }
}
John Rasch
A: 

Are you by chance handling viewstate in your code behind as well? If so then you need to handle the AJAX version of it as viewstate can often be lost on AJAX style pages. Try putting your buttons inside the update panel and see if you get the same behaviour if the panel has it's update mode set to conditional. Don't worry about the postback triggers if you do that.

The asynch triggers are only for items inside an update panel. any item outside of a panel will doa full postback by design.

<asp:UpdatePanel ID="pnlTasks" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate> 
<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:DropDownList ID="dropShippingSize" runat="server" CssClass="dropdownMandatory">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Middletone
Moving the UpdatePanel out to include the buttons as well as the dropdown sorted this out. Originally, I had the buttons and dropdowns in different cells in a table, and just set the UpdatePanel to wrap the dropdown cell. I figured I could move the whole table into the UpdatePanel. Thanks.
Bill
A: 

Hi, We had the same problem and it seems you will have to set the other "checked" property for radio buttons to "false". So please add the lines

radCD.Checked = False radDVD.Checked = False

naghi calin