There are several ways we do,
Simplest way
textBox1.Attributes["class"] = "class name";
Another way is to use Web Extension,
static class WebControlsExtensions
{
public static void AddCssClass (this WebControl control, string cssClass)
{
control.CssClass += " " + cssClass;
}
public static void RemoveCssClass (this WebControl control, string cssClass)
{
control.CssClass = control.CssClass.replace(" " + cssClass, "");
}
}
ctl.AddCssClass("ReadOnly");
ctl.RemoveCssClass("ReadOnly");
Hope this helps.
cheers