remove css class in code behind

后端 未结 8 883
说谎
说谎 2020-12-29 01:51

I have this control


I want to remove the

相关标签:
8条回答
  • 2020-12-29 02:06

    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());
    }
    
    0 讨论(0)
  • 2020-12-29 02:11

    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.

    0 讨论(0)
  • 2020-12-29 02:16
    lblName.Attributes.Add("class","urclassname"); //add class to lblName
    
    0 讨论(0)
  • 2020-12-29 02:19

    You can replace "required" with an empty string:

    lblName.CssClass = lblName.CssClass.Replace("required", "");
    
    0 讨论(0)
  • 2020-12-29 02:19

    To remove css Class from Code Behind

    lblName.Attributes["class"]=" ";
    
    0 讨论(0)
  • 2020-12-29 02:21

    Use this:

    object.CssClass= object.CssClass.Replace("MyClass", "");
    
    0 讨论(0)
提交回复
热议问题