在 ASP.NET 中动态加载 css [英] Loading css dynamically in ASP.NET
本文介绍了在 ASP.NET 中动态加载 css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在母版页中加载 css ...
I am loading a css in my master page ...
<link rel="stylesheet" href="css/mystyles.css" title="styles" type="text/css" />
现在我想根据 web.config 键动态加载它.有没有更好/标准的方法来做到这一点,或者我的想法是标准的方法?
Now I want to load this dynamically according to a web.config key. Is there a better/ standard way of doing this, or is my idea the standard way?
谢谢
推荐答案
选项 1:
您可以在 css 链接中添加 runat="server" 属性,并从可以动态设置的代码隐藏文件中设置 href 值.
You can add runat="server" attribute in your css link and set href value from code behind file where you can dynamically set it.
选项 2:
HtmlLink link = new HtmlLink();
link.Attributes["href"] = filename;
link.Attributes["type"] = "text/css";
link.Attributes["rel"] = "stylesheet";
Page.Header.Controls.Add(link);
这篇关于在 ASP.NET 中动态加载 css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文