Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading css dynamically in ASP.NET

Tags:

asp.net

themes

I am loading a css in my master page ...

<link rel="stylesheet" href="css/mystyles.css" title="styles" type="text/css" />

Now I want to load this dynamically according to a web.config key. Is there a better/ standard way of doing this, or is my idea the standard way?

Thanks

like image 298
grady Avatar asked Sep 13 '25 07:09

grady


1 Answers

Option 1:

You can add runat="server" attribute in your css link and set href value from code behind file where you can dynamically set it.

Option 2:

HtmlLink link = new HtmlLink();
link.Attributes["href"] = filename;
link.Attributes["type"] = "text/css";
link.Attributes["rel"] = "stylesheet";
Page.Header.Controls.Add(link);
like image 127
Nikhil Vaghela Avatar answered Sep 15 '25 01:09

Nikhil Vaghela