I have the following ASP.Net check box control added to a page:
Bu
I found a different answer to this, you can use the property
MyCheckBox.InputAttributes["class"] = "myClass";
to assign a class directly to an asp checkbox from the codebehind. Just noting this since I found this post through Google and the answer specified wouldn't work for me.
This post is quite old, but I'll post my solution to help anyone coming from google (like me).
You can use the child selector >
in jQuery, because the wrapping span
has the CssClass that you specified, and one input
child. In your code:
$('.myClass > input').addClass("myClass");
You could wrap it in a span
with a class.
Ok, when you apply a CssClass to the ASP.Net check box control it applies the class to a span that wraps the check box. Because the css class isn't applied directly to the element it doesn't override the class that has been applied to all input elements.Therefore I used jQuery to select the element and apply the necessary style.
$("input[type=checkbox]").addClass("myClass");
You can alos just set the css class like
<asp:CheckBox ID="cbValittu" runat="server" Checked='<%# Eval("Valittu")%>' Class="checBoks" />
Css class can look something like:
.checBoks input
{
width: 18px;
height: 18px;
vertical-align:middle;
}