【问题标题】:ASP.NET Dynamic StylesheetASP.NET 动态样式表
【发布时间】:2013-06-16 01:15:47
【问题描述】:

我想根据某些条件为控件应用样式表类。说

If (RepeatedUser)
{
    applyThisStyleSheetClass
}

else
{
   applyAnotherStyleSheetClass
}

我是否需要创建任何自定义控件/自定义属性/扩展方法来实现这一点?

【问题讨论】:

  • 一种在文档上使用 jQuery 的方法。准备检查是否使用了中继器然后更改类。

标签: asp.net stylesheet


【解决方案1】:

你可以试试扩展方法

 public static void ApplyCss(this WebControl control, string cssClass)
 {
        control.CssClass += " " + cssClass;
 }

你可以在你的代码中使用它

If (RepeatedUser)
{
   Label1.ApplyCss("GreenClass");
}

else
{
   Label1.ApplyCss("BlueClass");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    • 2011-09-28
    相关资源
    最近更新 更多