I am trying to conditionally include a css file depending on what browser the user is using. And I've been able to get it to work one way but not the way I want because it will require an extra style sheet. The way that works, in my Site.Master file I include a style sheet for ie8.
<link href="~/Styles/ie8.css" rel="Stylesheet" type="text/css" />
Then in Site.Master.cs in the Page_Load function.
if (!(browser.Type == "IE8" ||
browser.Type == "IE7" ||
browser.Type == "IE6" ||
browser.Type == "IE5"))
{
Page.Header.Controls.Add(new LiteralControl(
"<link rel=\" stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/ie.css") + "\" />"));
}
This works and the css is correct and using developer tools and compatibility in ie10 I can see it includes the correct css. But If I change my code to what should be equivalent. It doesn't work. Site.Master:
<link href="~/Styles/ie.css" rel="Stylesheet" type="text/css" />
Site.Master.cs
if ((browser.Type == "IE8" ||
browser.Type == "IE7" ||
browser.Type == "IE6" ||
browser.Type == "IE5"))
{
Page.Header.Controls.Add(new LiteralControl(
"<link rel=\" stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/ie8.css") + "\" />"));
}
If I put a breakpoint at Page.Header.Controls.Add I can see the function is getting called when in compatibility mode in ie10. But then when I go to dev tools and look for elements that use classes defined in ie8.css they aren't there like it was never included. What is going on here?