Re-enabling ASP.Net-rendered check box
15.05.2008 Четверг 20:35
If in a ASP.Net-rendered page you have a check box control (rendered by asp:CheckBox), and the corresponding server control has its Enabled property set to false, you won't be able to re-enable the check box in JavaScript just by setting its disabled property to false. This is because when rendering a check box from asp:CheckBox control with Enabled="false", ASP.Net encloses HTML check box (which is in fact a <input type="checkbox"> element) in a SPAN element, which has its disabled property set. Therefore to enable the check box you'll have to enable the SPAN too. This can be done with something like this:
cbRequired.disabled = false;
enableEnclosingSpan(cbRequired);
function enableEnclosingSpan(ctrl)
{
if(ctrl.parentElement.tagName == 'SPAN' && ctrl.parentElement.disabled == true)
ctrl.parentElement.disabled = false;
}