When you disable a CheckBox through it's server-side property, .NET adds a <span> tag around it so that any attachments are also disabled.
<span disabled="disabled"><input id="CheckBox1" type="checkbox" name="CheckBox1" disabled="disabled" /></span>
Doing a View Source with the page up in your browser would have shown you the above control declaration.
disabled=false to parent element seems the only way for IE8, but it does not work in FireFox. Firefox directly chages the "disabled" property and works fine. It hangs up when it tries to change the disabled attribute of the parent element. So a null checking
to parent element before changing it, works both in IE8 and FF.
matchbx27
Contributor
3432 Points
699 Posts
Code-Behind Syntax for Checkbox.Enabled = False
Apr 18, 2006 03:43 PM|LINK
I need to disable a checkbox in the Code-Behind, but be able to enable it with JavaScript on the Client Side.
I have the JS down and it will work as long the checkbox is not disabled on the code-behind.
Code-Behind things I've Tried
chkIsNetChange.Attributes.Add("disabled", "true") 'Doesn't work
chkIsNetChange.Enabled = False 'Doesn't work
chkIsNetChange.Style.Add("disabled", "true")
How can I disable the checkbox in the Code Behind and still be able to enable it with java script on the client side?
Thanks,
matchbx
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: Code-Behind Syntax for Checkbox.Enabled = False
Apr 18, 2006 04:43 PM|LINK
CodeBehind:
chkIsNetChange.Enabled = False
JavaScript:
<script language="JavaScript">
<!--
function enableCheckBox()
{
document.getElementById('chkIsNetChange').parentElement.disabled = false;
document.getElementById('chkIsNetChange').disabled = false;
}
// -->
</script>
NC...
matchbx27
Contributor
3432 Points
699 Posts
Re: Code-Behind Syntax for Checkbox.Enabled = False
Apr 18, 2006 04:59 PM|LINK
.parentElement.disabled is the part I was missing. Once I added that line of code to the JS Function...everything worked great.
Thanks a lot.
matchbx
ninel
Member
50 Points
20 Posts
Re: Code-Behind Syntax for Checkbox.Enabled = False
Apr 18, 2006 06:34 PM|LINK
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: Code-Behind Syntax for Checkbox.Enabled = False
Apr 19, 2006 11:50 AM|LINK
When you disable a CheckBox through it's server-side property, .NET adds a <span> tag around it so that any attachments are also disabled.
<span disabled="disabled"><input id="CheckBox1" type="checkbox" name="CheckBox1" disabled="disabled" /></span>
Doing a View Source with the page up in your browser would have shown you the above control declaration.
NC...
cosmicice
Member
16 Points
15 Posts
Re: Code-Behind Syntax for Checkbox.Enabled = False
May 03, 2010 06:05 AM|LINK
disabled=false to parent element seems the only way for IE8, but it does not work in FireFox. Firefox directly chages the "disabled" property and works fine. It hangs up when it tries to change the disabled attribute of the parent element. So a null checking to parent element before changing it, works both in IE8 and FF.
if(document.getElementById('chkIsNetChange').parentElement!=null){ document.getElementById('chkIsNetChange').parentElement.disabled = false; } document.getElementById('chkIsNetChange').disabled = false;gvdamn
Member
13 Points
30 Posts
Re: Code-Behind Syntax for Checkbox.Enabled = False
Jun 24, 2010 02:20 PM|LINK
For tackling the same issue for a RadioButtonList use
in code behind.
Source: http://www.codefrenzy.net/2008/06/19/enabling-disabling-aspnet-radio-buttons-using-code-behind-and-javascript/comment-page-1/#comment-225