Andrew Connell

ASP.NET, Javascript, and enabling disabled controls via client side script

Just ran across a little delima: I have a handful of ASP.NET controls that are initially loaded in a disabled state. The Framework generates these controls (and their text descriptions) like this: IsArea Well, when you try to disable the checkbox (or any control) using the standard JavaScript of: document.all.AdminConsole_IsAreaCheckbox.disbaled = false; It won't completely disable it... and thus, the value won't be sent down to the postback. What you need to do is enable the span as well... but the easiest way is just to rip out the disabled attributes all together: document.all.AdminConsole_IsAreaCheckbox.removeAttribute('disabled'); document.all.AdminConsole_IsAreaCheckbox.parentElement.removeAttribute('disabled'); ...

Just ran across a little delima: I have a handful of ASP.NET controls that are initially loaded in a disabled state. The Framework generates these controls (and their text descriptions) like this:

IsArea

Well, when you try to disable the checkbox (or any control) using the standard JavaScript of:

document.all.AdminConsole_IsAreaCheckbox.disbaled = false;

It won’t completely disable it… and thus, the value won’t be sent down to the postback. What you need to do is enable the span as well… but the easiest way is just to rip out the disabled attributes all together:

document.all.AdminConsole_IsAreaCheckbox.removeAttribute(‘disabled’); document.all.AdminConsole_IsAreaCheckbox.parentElement.removeAttribute(‘disabled’);

Andrew Connell
Founder & Chief Course Artisan, Voitanos LLC. | Microsoft MVP
Written by Andrew Connell

Andrew Connell is a web developer with a focus on Microsoft Azure & Microsoft 365. He’s received Microsoft’s MVP award every year since 2005 and has helped thousands of developers through the various courses he’s authored & taught. Andrew’s the founder of Voitanos and is dedicated to delivering industry-leading on-demand video training to professional developers. He lives with his wife & two kids in Florida.