2013-09-25 30 views
0

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

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

请帮

+0

你给解释你期望没有太大传达什么样的需求的原因。如果您有一个您不想更改的css类,请创建该类的副本并对其进行修改,然后使用该类。或者使用内联样式。可以有几种解决方案,但事实是你的问题并不清楚。 –

回答

1

你正在试图解决的问题的方法似乎并不符合逻辑。根据stylefolder属性临时修改css看起来很疯狂。您可以不使用内联样式,具体取决于属性值并将一些数据存储在会话中?

0

制作一个单独的文件为用户控制和在运行时加载的条件基础上的文件这样

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); 
    } 
}