Thursday, May 10, 2012

How to dynamically add CSS file in ASP.NET

Here i will show how to add css file to page in code behind.For this i have created a custom HTML link control and assign the styles sheet URL ,set remaining properties. We can see one more thing here is creating HTML control dynamically
In aspx page:
<link href="~/styles.css" rel="Stylesheet" type="text/css" />

       HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/Styles.css");
This.Header is used to add the link to aspx page

No comments: