Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a specific CSS file from an ASP.NET Theme?

Tags:

asp.net

themes

I'm making a website that will have to render correctly on FF/IE6/IE7/Opera/Safari. IE6 came as a late requirement (when I had done all the other browsers) and it just has to be useable, not necessarily the same as on the other browsers. Now I'm tweaking it so that it's useable on IE6 as well.

To this end I've created another stylesheet in my theme called IE6_override.css. As you might have guessed, I want it to be applied only when the browser is IE6. Conditional comments would perfect for this.

The only problem is - ASP.NET renders a <link> tag for every CSS file that is in the theme's folder, thus including this file unconditionally on all browsers.

I would like to stick to themes because it's completely feasible that we might create more skins for our application later (if the customers desire that).

Is there any way how I can make ASP.NET exclude this specific .CSS file from its auto-including?

Added: Thank you for your answers! In the end I found a workaround. Due to some other styling problems I've asked about earlier, I'm forced to have a IE6-workaround Javascript as well. Thus I prefixed all my IE6-specific rules with a .ie6_dummy class selector and then removed it in JS upon page loading. :)

like image 432
Vilx- Avatar asked Dec 09 '22 21:12

Vilx-


2 Answers

Yes you can... You can just remove the specific page header control in code behind. The css files are added automatically through theming, but u can remove them again after. Like for example u can put in the page load of your master file:

Page.Header.Controls.Remove(YourCssFile);

Or if you wanna have all the css files removed at the same time:

var themePath = string.Format("~/App_Themes/{0}", Page.Theme);
var removeCandidate = Page.Header.Controls.OfType<HtmlLink>().Where(link => link.Href.StartsWith(themePath)).ToList();
removeCandidate.ForEach(Page.Header.Controls.Remove);
like image 120
WtFudgE Avatar answered Jan 18 '23 08:01

WtFudgE


I don't think you can. We stopped using the App_Themes folder for exactly that reason. This also saved us having to prefix every css file with a number so they load in the right order.

like image 43
Nick Avatar answered Jan 18 '23 07:01

Nick