I have a series of checkboxes that I'm adding to a panel programmatically. I set the CssClass property but instead of setting the CSS class of the control it just wraps it in a span with that CSS class. Is there a way to make it give the checkbox the class? I need the class on the actual checkbox because in javascript I'm selecting by class.
Here's my code:
CheckBox checkbox = new CheckBox();
checkbox.Text = checkboxText;
checkbox.ID = checkboxID;
checkbox.CssClass = "chkRoles";
pnlMandatoryRoles.Controls.Add(checkbox);
pnlMandatoryRoles.Controls.Add(new LiteralControl("<br>"));
Replace:
checkbox.CssClass = "chkRoles"
With:
checkbox.InputAttributes["class"] = "chkRoles"
Ues Like below
CheckBox checkbox = new CheckBox();
checkbox.Text = "checkboxText";
checkbox.ID = "checkboxID";
checkbox.InputAttributes["class"] ="chkRoles";
pnlMandatoryRoles.Controls.Add(checkbox);pnlMandatoryRoles.Controls.Add(new LiteralControl("<br>"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With