Tricks for ASP .NET Checkboxes
August 20, 2012
Recently I have been dealing with situations where I need to implement functionality involving ASP .NET checkboxes. I’m sure if you are reading this, then you have had your fair share of annoyances with these fun controls. Here are a few tricks that I’ve learned from dealing with them:
 This is how an ASP .NET checkbox actually renders as HTML
This can make it a pain to work with instead of just having the input control. So I’m sure you have dealt with issues of trying to add attributes or wanted to add attributes to the actual input control and not that wrapping span tag. That brings us to trick 2:
 If you are using C# and want to add attributes to the actual input control and not the span, here is how you do it:
By doing that, you are telling the control to add the attribute to the input tag and not the span wrapper tag.
 Something I just found out today: if you want to filter by visibility using jQuery, you either need to use the ID of your control, make sure your class is added to the input control, or customize the filter function to target the CSS properties. Here is how you can do it any of the ways:
Using the ID:
Adding your class to the input control:
Here you will just follow the advice of trick 2 by adding the attribute in the code behind
And now using that class to filter with jQuery:
Or with the last options, you can do it all using jQuery by customizing the filter function to look at the CSS:
Those are the tricks I’ve come across so far. If you have any of your own, I would be very interested to here. Will update if I find anymore helpful tips.