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

后端 未结 7 2148
清歌不尽
清歌不尽 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:31

    I find it better to use REGEX replace since replacing class could exist as partial name in other classes which would break them. So I'm using the following extension method:

    public static void RemoveClass(this WebControl control, string classToRemove)
    {
        if (control == null)
            return;
    
        control.CssClass = Regex.Replace(control.CssClass, @"(^|\s)" + classToRemove + @"($|\s)", " ");
    }
    

提交回复
热议问题