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

I am creating a website that will correctly display on FF / IE6 / IE7 / Opera / Safari. IE6 came as a last resort (when I made all other browsers), and it just has to be useful, not necessarily the same as in other browsers. Now I configure it so that it can be used on IE6 as well.

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

The only problem is ASP.NET displays a tag <link>for each CSS file that is in the theme folder, thus including this file unconditionally in all browsers.

I would like to adhere to because it is quite possible that we could create more skins for our application later (if clients wish).

Is there any way to get ASP.NET to exclude this particular .CSS file from its automatic inclusion?

Added: Thanks for your answers! In the end, I found a workaround. Due to some other design issues that I mentioned earlier, I also have to use Javascript with IE6. This way, I prefix all my IE6 rules with the class selector .ie6_dummyand then delete it in JS when the page loads. :)

+3
source share
4 answers

, . App_Themes. , css , .

+5

, ... . css theming, . , , :

Page.Header.Controls.Remove(YourCssFile);

css :

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);
+6

, CSS. , , . ( ).

+1

There are several posts on the Internet that seem to solve your problem - they are looking for "Conditional Comments in Asp.net Themes". I came across those that look like they can help:

First of all, the issue of releasing multimedia with theme style sheets will also be considered.

+1
source

Source: https://habr.com/ru/post/1703296/


All Articles