Tuesday, June 23, 2009

How to add link to a css file in content page

Try this

In VB

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim css As HtmlGenericControl
css = New HtmlGenericControl
css.TagName = "style"
css.Attributes.Add("type", "text/css")
css.InnerHtml = "@import ""/foobar.css"";"
Page.Header.Controls.Add(css)
End Sub

In C#

protected void Page_Init(object sender, System.EventArgs e)
{
HtmlGenericControl css;
css = new HtmlGenericControl();
css.TagName = "style";
css.Attributes.Add("type", "text/css");
css.InnerHtml = "@import \"/foobar.css\";";
Page.Header.Controls.Add(css);
}

No comments: