I have this control
I want to remove the
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());
}
NOTE: whether you add or replace a css class in codeBehind, remember to include equivalent attributes in both classes i.e. both having background-color, font-family...etc. because otherwise you may be fooled to think that the class never switched even though it did but didn't update the equivalent attributes.
lblName.Attributes.Add("class","urclassname"); //add class to lblName
You can replace "required" with an empty string:
lblName.CssClass = lblName.CssClass.Replace("required", "");
To remove css Class from Code Behind
lblName.Attributes["class"]=" ";
Use this:
object.CssClass= object.CssClass.Replace("MyClass", "");