I have an ASP.NET app and I am using jQuery to toggle the enablement of some fields. Here's a rough diagram of the UI:
__ checkbox1
o radio1
o radio2
text1
text2
When checkbox1 is checked, I enable radio1 and radio2. When radio2 is selected, I enable text1 and text2.
What is happening in my case is after the user checks the checkbox, and the radio buttons are enabled, if the user selects radio2 and submits the form, the selection automatically goes back to radio1.
This problem does not occur if I don't dynamically enable the radio buttons using jQuery. So I am wondering if something with how the radio buttons are enabled doesn't play nicely with how ASP.NET works with radio buttons.
When the checkbox value changes, I call the following helper method in my code. Since ASP.NET will add a around a disabled radio button, I make sure to turn off the disabled flag on both the span and the input.
function setRadioEnabled(id, enabled) {
var radio = jQuery(id);
var parentSpan = radio.parent();
if (enabled) {
parentSpan.removeAttr('disabled');
radio.removeAttr('disabled');
} else {
radio.attr('disabled', 'disabled');
parentSpan.attr('disabled', 'disabled');
}
}
The radio buttons are defined as ASP:RadioButton tags and they share a GroupName even though they are in different table rows. This results in two input type=radio instances with a matching name value.
I confirmed that my radio was being reset as the page was submitted by putting a breakpoint in the postback method and seeing the value of radio1.Checked was true and radio2.Checked was false. What could be causing the page to switch the value of my radio buttons?
Thanks in advance, David