开发者

Possible to add a class to an existing class attribute of object via C#?

I have an existing class for an开发者_C百科 input, is it possible to add an additional class for the object in C#.net, instead of doing a if/else and not having a preset class on the object in the first place?


txtField.CssClass = "first_class";
// Output: class="first_class"

txtField.CssClass += " another_class";
// Output: class="first_class another_class"


Try this, works for me.

public static class ControlUtility
{
    public static void AddCssClass(WebControl control, string cssClass)
    {
        control.CssClass += " " + cssClass;
    }
    public static void RemoveCssClass(WebControl control, string cssClass)
    {
        control.CssClass = control.CssClass.Replace(" " + cssClass, "");
    }
}

ControlUtility.RemoveCssClass(lnkletter, "ln-enabled");
ControlUtility.RemoveCssClass(lnkletter, "ln-disabled");


this didn't work

txtSubject.CssClass.Replace("text-single", "text-single subjectDisabled");

found the solution here:

Best way to change CSS Classes from code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜