Click here to Skip to main content
15,897,519 members

RadioButtonList Postback issue when selected by code behind.

virang_21 asked:

Open original thread
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.
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900