AddCssClass

public static void AddCssClass(this WebControl control, string cssClass)
{
    control.CssClass += " " + cssClass;
}
Example:
ASP.NET Markup:
<asp:Label ID="MyLabel" runat="server" CssClass="defaultClass" />

C# Codebehind:
if (userIsLoggedIn)
{
    MyLabel.AddCssClass("loggedIn");
}
else
{
    MyLabel.AddCssClass("anonymous");
}

Description

Adds a css class to the webcontrol. Instead of having to pass one string to the CssClass property, you can add them one by one with the AddCssClass extension method. This can come in handy when a webcontrol has a default class (from the ASP.NET markup) and then needs additional classes based on a condition (like whether or not a user is logged in).

Details

Double click on the code to select all.

 

;