最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Setting Radio Button enableddisabled via CSS - Stack Overflow

programmeradmin5浏览0评论

Is there a way to make a Radio Button enabled/disabled (not checked/unchecked) via CSS?

I've need to toggle some radio buttons on the client so that the values can be read on the server, but setting the 'enabled' property to 'false' then changing this on the client via javascript seems to prevent me from posting back any changes to the radio button after it's been enabled.

See: ASP.NET not seeing Radio Button value change

It was remended that I use control.style.add("disabled", "true") instead, but this does not seem to disable the radio button for me.

Thanks!

Is there a way to make a Radio Button enabled/disabled (not checked/unchecked) via CSS?

I've need to toggle some radio buttons on the client so that the values can be read on the server, but setting the 'enabled' property to 'false' then changing this on the client via javascript seems to prevent me from posting back any changes to the radio button after it's been enabled.

See: ASP.NET not seeing Radio Button value change

It was remended that I use control.style.add("disabled", "true") instead, but this does not seem to disable the radio button for me.

Thanks!

Share Improve this question edited Mar 23, 2020 at 6:18 Awais 4,9024 gold badges19 silver badges42 bronze badges asked Sep 25, 2008 at 14:16 Chris BurgessChris Burgess 5,83513 gold badges57 silver badges69 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

Disabled is a html attribute, not a css attribute.

Why can't you just use some jQuery

$('#radiobuttonname').attr('disabled', 'true');

or plain old javascript

document.getElementById(id).disabled = true;

To the best of my knowledge CSS cannot affect the functionality of the application. It can only affect the display. So while you can hide it with css (display:none) you can't disable it.

What you could do would be to disable it on page load with javascript. There are a couple ways to do this but an easy way would be to do something like

<script>document.getElementById('<%=CONTROLID%>').disabled=true;</script>

and put that in your .aspx file at the top below the body tag.

CSS is for changing presentation. JavaScript is for changing behaviour. Setting an element to be enabled or disabled is behaviour and should done in JavaScript.

if you look at the html generated by asp for a disabled radio button, you'll see that the button is embedded in a span tag, and the disabled attribute of the span is set to true. perhaps javascript to target an enclosing span will do the trick for you

发布评论

评论列表(0)

  1. 暂无评论