在 ASP.NET 中动态设置 CSS 文件链接






3.55/5 (23投票s)
2004 年 12 月 3 日

134711
VB.NET 代码行,用于动态设置 CSS 文件链接。
引言
我在网上很难找到这个,所以我想把它发布在 CodeProject.com 上。
我希望能够动态设置 CSS 文件链接。例如,让用户能够个性化他们的网站,改变外观和感觉。
只需在传统的 link
标签中添加一个 runat
属性。 ID
属性必须存在,并且标签必须正确关闭(不像 HTML)。
<head>
<link id="MyStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>
然后在你的 Page_Load
中,简单地添加一个 "href
" 属性如下
Sub Page_Load(Sender As Object, E As EventArgs)
If Not (IsPostBack)
MyStyleSheet.Attributes.Add("href","/css/flostyle.css")
End If
End Sub
没什么花哨的,很简单,但非常有用。它也适用于 meta 标签。