Reputation: 3479
When my ASP.NET page does a postback in IE7, all the CSS is lost. I am not using Themes and are including the CSS from the Masterpage in code behind.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AddStylesheetInclude("/static/css/global.css");
AddStylesheetInclude("/static/css/sifr.css");
}
And my code to actually do the adding:
public virtual void AddStylesheetInclude(String url)
{
HtmlLink link = new HtmlLink();
link.Attributes["type"] = "text/css";
link.Attributes["href"] = url;
link.Attributes["rel"] = "stylesheet";
Page.Header.Controls.Add(link);
}
It works perfectly fine in Firefox, just IE. To add more context, in the CSS file included, it uses @import
to include the rest.
It works if I take all the @import
rules and have it included in the actual HTML.
Upvotes: 0
Views: 3256
Reputation: 30364
After doing more research on your problem I found out the reason is doesn't work with the link is because (http://www.broken-links.com/2007/02/15/ie7-and-import-media-types/ )IE7 isn't compatible with @import. Which is kind of a good thing, because IE7 fixed the '!important' and '* html' debugging hacks, so without the @import bug there wouldn't be an easy way to debug in IE7. But I am sure they will fix it next time around (5 years or so?) and at that point debugging in IE* will be h*ll.
So I guess this is the only way for now to try adding the css script on the client side so it will always remain rendered on the page. after you build with the link included of the css file your IntelliSense should pick up your classes when you try to add classes to controls in your source file..if that does not happen something may be wrong with your link to the file, so instead incorporate your css code in your source as so:
<style type="text/css">
.highlight{
background-color: #C0DDE0;
}
</style>
and you should be able to something like this
<table id="table1" class="highlight"/>
Upvotes: 1
Reputation: 52420
Have you verified that the tag is still on the page after a postback? I seem to remember something about difficulties manipulating the HEAD tag reliably.
Upvotes: 0
Reputation: 2479
If the css still doesn't work even after you have placed a link-tag directly in the head, i'd say that there isn't anything wrong with the way you include the css, but rather the css-files themselves.
Try including them all without the @import directly in the head. That way you can rule out any issues with the import.
Upvotes: 0