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!
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!
Share Improve this question asked Sep 24, 2008 at 21:44 Chris BurgessChris Burgess 5,83513 gold badges57 silver badges69 bronze badges 1- How are you disabling the said radio buttons? Are you disabling them in JavaScript or are you doing that via server side code? – Adhip Gupta Commented Sep 25, 2008 at 13:13
3 Answers
Reset to default 6This has to do with how ASP.NET postback data. If a control is disabled control.enabled = false
when 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 of control.enabled = false
, you use control.attributes.add("disabled", "disabled")
.
apparently disabled is an html attribute not a css attribute. if you disable a radio button on the server side in asp and then check the rendered html, the radio button is embedded in a span tag with its disabled attribute set to true. You might try targeting the span of the button instead (parent element, it has no id) and setting disabled=false in your javascript to see if that works
This isn't working for me.
I added:
Me.rbSolid.Style.Add("background-color", "red")
Me.rbSolid.Style.Add("disabled", "true")
and the background style works but the disabled
did not. It's still editable when the form renders.
Here's the source after load:
<span style="font-family:Verdana;font-size:8pt;background-color:red;Disabled:true;">
<input id="ctl00_MainLayoutContent_WebPanel4_rbSolid" type="radio" name="ctl00$MainLayoutContent$WebPanel4$DetailType" value="rbSolid" onclick="styleLookupChanged(this);"/>
<label for="ctl00_MainLayoutContent_WebPanel4_rbSolid">Solid</label>
</span>