admin 管理员组文章数量: 1086019
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>
本文标签: javascriptASPNET not seeing Radio Button value changeStack Overflow
版权声明:本文标题:javascript - ASP.NET not seeing Radio Button value change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744099064a2533412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论