asp.net 动态引用样式表代码
程序员文章站
2024-03-08 16:58:46
1. 添加css样式: style style = new style(); style.forecolor = system.drawing.color.navy; st...
1. 添加css样式: style style = new style();
style.forecolor = system.drawing.color.navy;
style.backcolor = system.drawing.color.lightgray;
this.header.stylesheet.createstylerule(style, null, "body");
2. 链接外部的css样式表: htmllink link = new htmllink();
link.attributes.add("type", "text/css");
link.attributes.add("rel", "stylesheet");
link.attributes.add("href", "~/newstyle.css");
this.header.controls.add(link);
方法3 aa.aspx.cs public string m_stylesrc = string.empty; //公共变量 ,样式文件路径
private void page_load(object sender, system.eventargs e) {
m_stylesrc = "../xxx.css"; //页面加载时赋值 }
}
aa.aspx <link href="<%=m_stylesrc%>" type="text/css" rel="stylesheet">
方法4 下面这个方法没试过,不知是否能用
protected void page_onload(object sender, eventargs e) {
page.stylesheettheme = "../css/infomore.css";
}
方法5 页面:
<link href="" rel="stylesheet" type="text/css" id="css" runat="server"/>
后台
this.css.href = "css文件路径";
style.forecolor = system.drawing.color.navy;
style.backcolor = system.drawing.color.lightgray;
this.header.stylesheet.createstylerule(style, null, "body");
2. 链接外部的css样式表: htmllink link = new htmllink();
link.attributes.add("type", "text/css");
link.attributes.add("rel", "stylesheet");
link.attributes.add("href", "~/newstyle.css");
this.header.controls.add(link);
方法3 aa.aspx.cs public string m_stylesrc = string.empty; //公共变量 ,样式文件路径
private void page_load(object sender, system.eventargs e) {
m_stylesrc = "../xxx.css"; //页面加载时赋值 }
}
aa.aspx <link href="<%=m_stylesrc%>" type="text/css" rel="stylesheet">
方法4 下面这个方法没试过,不知是否能用
protected void page_onload(object sender, eventargs e) {
page.stylesheettheme = "../css/infomore.css";
}
方法5 页面:
<link href="" rel="stylesheet" type="text/css" id="css" runat="server"/>
后台
this.css.href = "css文件路径";