Thursday, June 14, 2012

How to: Add CSS file in ASP.NET at runtime

Adding CSS file in ASP.NET programatically

HtmlGenericControl si = new HtmlGenericControl();
si.TagName = "link";
si.Attributes.Add("type", "text/css");
si.Attributes.Add("href", "css/module.css");
si.Attributes.Add("rel", "stylesheet");


  1. This is a simple ASP.NET code to what I have seen before in one forum being used for the same purpose. That was really confusing and didn't understand what exactly it want to say. This code is really easy to follow and even understable to what it means.

  2. Hi, thanks for sharing. That is very simple piece of code. If you want to get such simple solutions, just call this guys I'm sure they will help you.