Remove a CSS class from HTML element in the code behind file

后端 未结 7 2066
清歌不尽
清歌不尽 2021-02-19 03:15

I have the following on my interface / webform:

Now I have a condition in my

7条回答
  •  有刺的猬
    2021-02-19 03:40

    How to remove ONE CSS class from a control using .NET

    If a control has several classes you can remove one of those classes by editing the class string. Both of these methods require assigning an ID to the HTML element so that you can target it in the code behind.

    
    

    VB.NET

    mydiv.CssClass = mydiv.CssClass.Replace("forceHeight", "").Trim()
    

    C#

    mydiv.CssClass = mydiv.CssClass.Replace("forceHeight", "").Trim();
    

    OR using html generic control

    VB.NET

    mydiv.Attributes("class") = mydiv.Attributes("class").Replace("forceHeight", "").Trim()
    

    C#

    mydiv.Attributes["class"] = mydiv.Attributes["class"].Replace("forceHeight", "").Trim();
    

    Optional Trim to remove trailing white space.


    How to remove ALL CSS classes from a control using .NET

    VB.NET

    mydiv.Attributes("class") = ""

    C#

    mydiv.Attributes["class"] = "";

提交回复
热议问题