RemoveCssClass

public static void RemoveCssClass(this WebControl control, string cssClass)
{
	var classes = from c in control.CssClass.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				  where !c.Equals(cssClass, StringComparison.OrdinalIgnoreCase)
				  select c;

	control.CssClass = String.Join(" ", classes);
}
Example:
ASP.NET Markup:
ASP.NET Markup:
<asp:Label ID="MyLabel" runat="server" CssClass="defaultClass loggedIn" />

C# Codebehind:
if (!userIsLoggedIn)
{
    MyLabel.RemoveCssClass("loggedIn");
}

Description

Removes a css class from the webcontrol. Let's say you have a webcontrol (a label for example) with more than one css class: "defaultClass loggedIn". With the RemoveCssClass extension method, you can easily remove one of them.

Details

Double click on the code to select all.

 

;