I have this control
<asp:Label ID="lblName" runat="server" Text="My Name" CssClass="required regular" />
I want to remove the required
class from code behind, how can I do that?
The syntax for Removing CSS classes to an element:removeClass(class_name);
To remove a class from an element, you use the remove() method of the classList property of the element.
You can replace "required" with an empty string:
lblName.CssClass = lblName.CssClass.Replace("required", "");
Just a slightly more generic way of doing the same - should rule out potential errors where a css class might occur elsewhere in the CssClass property.
public void RemoveCssClass(WebControl controlInstance, String css) { controlInstance.CssClass = String.Join(" ", controlInstance.CssClass.Split(' ').Where(x => x != css).ToArray()); }
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