Click here to Skip to main content
12,894,930 members (62,567 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
This is rather interesting issue I am facing at the moment. I have a radio button list on my page with three options "Yes", "No" and "Maybe". It has AutoPostBack set to true to fire SelectedIndexChanged event.

<asp:RadioButtonList ID="rblTakeHoliday" runat="server" AutoPostBack="True"
                    <asp:ListItem Value="Yes">Yes</asp:ListItem>
                    <asp:ListItem Value="No">No</asp:ListItem>
           <asp:ListItem Value="Maybe">Maybe</asp:ListItem>

User selects one of the option from RadioButtonList and based on selection four gridviews are populated with data and user can select some rows from those gridviews and submit this information. Up to this point it works fine.

If user later come to same page again and want to change holiday preference from whatever selected before to something new I want to display his previous holiday selection. So I fetch his previous selection from database and make one of the radio button selected in code behind as follow (For example user selected "Maybe" as an option initially):

rblTakeHoliday.Items[0].Selected = false;
rblTakeHoliday.Items[1].Selected = false;
rblTakeHoliday.Items[2].Selected = true;

Now user is playing with those three radio buttons on the page. The SelectedIndexChanged event will fire when user selects "Yes" or "No" radio button but it will not fire for "Maybe" radio button as it rendered with checked="checked" in browser because I set it as Selected= "true" in code behind. So for example If user selects option "Yes" the SelectedIndexChanged event will fire. If user go back to "Maybe" option the SelectedIndexChaged event will not get fired. Is there any work around to this ? I want to make radio button list fire its SelectedIndexChanged event on any radio button selection.

I know this is the issue because of setting radio button selected in code behind.
Posted 13-Oct-10 13:37pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Need more details on which state you are setting the values in page behind, is this Page:Load? if so try this


Another workaround is the way you are setting data, you should use

<code>// Suppose at databse value "MayBe" is saved. Assign it into a variable the try to set
String myValue="MayBe";

Hope this will help.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Apparently it turn out to be an issue with third party AJAX RAD controls ( Telerik Controls and AjaxSettings section of those controls )I am using in the application. I had to move RadioButtonList inside panel and use that panel ID as control of AjaxSettings for Telerik.

I created a test page to test if it happens without AJAX or not and finally able to nail the problem.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I had a similar experience where the radiobuttonlist would fire on one selection but not when I reselected the orginal selection in the list.  This is a wierd fix, but I had to do this.
<pre lang="c#">
protected void rblTakeHoliday_SelectedIndexChanged(object sender, EventArgs e)
    foreach (ListItem item in radio.Items)
        if (item.Selected)
           item.Selected = true;
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Get it inside an update panel, with property "ChildrenAsTriggers" on true. This solve the issue for me.
<pre lang="HTML">
<asp:UpdatePanel ID="updpnlRbtnLocalidad" runat="server" UpdateMode="Conditional" <b>ChildrenAsTriggers="true"</b>>
    <asp:Panel ID="pnlrbtnLocalidad" runat="server">
      <asp:RadioButtonList ID="rbtnLocalidad" runat="server" AutoPostBack="true"   OnSelectedIndexChanged="rbtnLocalidad_SelectedIndexChanged">
        <asp:ListItem Text="Lugar" Value="4"></asp:ListItem>
        <asp:ListItem Text="Pais" Value="3"></asp:ListItem>
        <asp:ListItem Text="Provincia" Value="2"></asp:ListItem>
        <asp:ListItem Text="Departamento" Value="1"></asp:ListItem>
        <asp:ListItem Text="Localidad" Value="0"></asp:ListItem>
asmaaelshabaka 6-May-14 8:30am
i did that but still does not postback
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

I have the same problem

can some one help me i have three items in my radiobuttonlist only the first and second item cam post back but the third item does not postback
CHill60 6-May-14 8:58am
If you have a question of your own then use the "Ask a question" link. Not many people will see your question if you post it as a solution to an old question, and you will get downvoted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 6 May 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100