I have a form with some radio buttons that are disabled by default.
When a value gets entered into a text box, the radio buttons are enabled via javascript. The user then selects one of the radio buttons and clicks on a submit button which posts back to the server.
When I get back to the server, the radio button that user clicked is not showing as checked. I’ll use ‘rbSolid’ as the radio button I’m focusing on.
I handle the ‘onclick’ event of the radio buttons, but I don’t have the function doing anything yet other than firing:
Me.rbSolid.Attributes.Add(‘onclick’, ‘styleLookupChanged(this);’)
On the client, this enables the radio button when the textbox value is changed:
document.getElementById(‘ctl00_MainLayoutContent_WebPanel4_rbSolid’).disabled = false;
I then click the radio button then post back via a button, but back on the server this is always false:
If Me.rbSolid.Checked Then…
If I have the radio button enabled by default, it shows as checked correctly.
Thanks for any help!
This has to do with how ASP.NET postback data. If a control is disabled
control.enabled = falsewhen the page is rendered than the values will not be posted back to the server. How I have solved it in the past is to set the disabled flag using attributes tags instead of using the Enabled property. So instead ofcontrol.enabled = false, you usecontrol.attributes.add("disabled", "disabled").