Click here to Skip to main content
Rate this: bad
good
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"
                    onselectedindexchanged="rblTakeHoliday_SelectedIndexChanged"
                    RepeatDirection="Horizontal">
                    <asp:ListItem Value="Yes">Yes</asp:ListItem>
                    <asp:ListItem Value="No">No</asp:ListItem>
           <asp:ListItem Value="Maybe">Maybe</asp:ListItem>
                </asp:RadioButtonList>
 
 
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 14:37pm
virang_2111.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi,
 
Need more details on which state you are setting the values in page behind, is this Page:Load? if so try this
 
if(!IsPostBack){//SET YOUR RADIO BUTTON LIST DATA}
 
Another workaround is the way you are setting data, you should use
 
// Suppose at databse value "MayBe" is saved. Assign it into a variable the try to set
String myValue="MayBe";
rblTakeHoliday.SelectedIndex=
rblTakeHoliday.Items.IndexOf(rblTakeHoliday.Items.FindByValue(myValue));
 
Hope this will help.
  Permalink  
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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;
    }
}
</pre>
  Permalink  
Rate this: bad
good
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.
 
Example:
<pre lang="HTML">
<asp:UpdatePanel ID="updpnlRbtnLocalidad" runat="server" UpdateMode="Conditional" <b>ChildrenAsTriggers="true"</b>>
  Permalink  
Comments
asmaaelshabaka at 6-May-14 8:30am
   
i did that but still does not postback
Rate this: bad
good
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
  Permalink  
Comments
CHill60 at 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
0 Sergey Alexandrovich Kryukov 410
1 OriginalGriff 230
2 DamithSL 175
3 Maciej Los 135
4 Dave Kreskowiak 120
0 OriginalGriff 7,740
1 DamithSL 5,694
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,061
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 6 May 2014
Copyright © CodeProject, 1999-2014
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