【问题标题】:Change the content of a Css Class through Code Behind in asp.net在 asp.net 中通过 Code Behind 改变一个 Css 类的内容
【发布时间】:2013-10-01 03:00:05
【问题描述】:

我需要通过 asp.net 后面的代码更改一个 css 类的 CONTENTS。我需要这样做的原因是因为我有一个外部用户控件,它使用一个名为“stylefolder”的属性而不是普通的 cssclass。

我真的没有想法,我试图打开 css 文件并替换文本,但之后我还需要保存它。所以 css 文件被永久修改,这是我不想要的。

请帮忙

【问题讨论】:

  • 你给出的解释你所期望的需求的理由并没有传达太多信息。如果您有一个不想更改的 css 类,请创建该类的副本并修改它,然后改用它。或者使用内联样式。可以有多种解决方案,但事实是您的问题并不清楚。

标签: asp.net css class


【解决方案1】:

您尝试解决问题的方式似乎不合逻辑。根据 stylefolder 属性临时修改 css 似乎很疯狂。你不能根据属性值使用内联样式并在会话中存储一些数据吗?

【讨论】:

    【解决方案2】:

    为该用户控件创建一个单独的文件,并在运行时像这样根据条件加载文件

    protected void Page_Init(object sender, EventArgs e)
    {
      if (usercontrol)
        {
          // load the css relateed to user control
           HtmlLink cssPdf = new HtmlLink();
           cssPdf.Href = "path to user control file";
           cssPdf.Attributes["rel"] = "stylesheet";
           cssPdf.Attributes["type"] = "text/css";
           cssPdf.Attributes["media"] = "all";
           Page.Header.Controls.Add(cssPdf);
        }
      else
        {
          //load regular file
          HtmlLink cssPdf = new HtmlLink();
          cssPdf.Href = "path to regular file";
          cssPdf.Attributes["rel"] = "stylesheet";
          cssPdf.Attributes["type"] = "text/css";
          cssPdf.Attributes["media"] = "all";
          Page.Header.Controls.Add(cssPdf);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 2015-03-31
      • 1970-01-01
      相关资源
      最近更新 更多