在.asp中如何引用CSS样式表?

html-css019

在.asp中如何引用CSS样式表?,第1张

可以定义一个类:

static public class AddStyle{

 static public void AddStyleSheet(Page page, string cssPath)

 {

HtmlLink link = new HtmlLink()

link.Href = cssPath

link.Attributes["rel"] = "stylesheet"

link.Attributes["type"] = "text/css"

page.Header.Controls.Add(link)

 }

}

然后在页面中调用该类的静态方法:

在page_load方法中:

protected void Page_Load(object sender, EventArgs e)

{

 AddStyle.AddStyleSheet(this.Page, "css/test.css")

//CSS文件放在这里.

}

1、Button1.Style.Add(HtmlTextWriterStyle.Color,"red")

2、Button1.Style.Add("color","red")

3、Button1.Attributes.Add("style","color:red")

<asp:Button ID="Button1" style="color:red"></asp:Button>是不管用的。