March 2009 Blog Posts

Add client-side onchange handler to ASP.NET CheckBox control

The ASP.NET CheckBox control offers a convenient abstraction on top of the standard HTML input type="checkbox" control, by marrying a checkbox with a label. Ordinarily, the ASP.NET checkbox works just fine, but if you wanted to have a client-side javascript function triggered when the checkbox is toggled, there is no built-in mechanism to do that. The usual things to try when one wants to add client-side functionality to ASP.NET controls won't work because the CheckBox control wraps the checkbox input control and the label inside of a span. So, if one were to just add an "onchange" or "onclick" handler either...