HtmlLink myHtmlLink = new HtmlLink(); myHtmlLink.Href = "~/StyleSheet.css"; myHtmlLink.Attributes.Add("rel", "stylesheet"); myHtmlLink.Attributes.Add("type", "text/css"); // Add the HtmlLink to the Head section of the page. Page.Header.Controls.Add(myHtmlLink); } }
2. 代码动态加入public class YourPage : PageBase
{
// ...
}public class PageBase : System.Web.UI.Page
{
protected override void OnInit(EverntArgs e) {
base.OnInit(e);
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = "~/StyleSheet.css";
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css"); // Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink); }
}
http://www.entlib.net.cn/html/2008-07/46.html
可以添加一个App_Themes目录