ASP.NET Application Looks Like Hell on IE7?

The other day, my wife explained that she has been telling her team to use IE6, since IE7 breaks her ASP.NET application.  She has been keeping this a secret from me, since obviously it is a grave violation of trust between mates.  She came to me only because IT is forcing upgrade of IE7 on her team, and she needed help.

It took me only a few moments to find the problem.  ASP.NET is pretending to issue XHTML and claims to adhere to strict doctype.  At the top of the .aspx page was an XHTML doctype (click the image to see it; curses on WordPresses buggy “security filter”):

XHTML doctype

I deleted it, and now the site renders the same in IE7 as in IE6.

~

This simple trick should fix your problem.  If you’re interested in hearing why, please read on. 

The short explanation is this: IE7 is far more standards-conformant than IE6, so pages that rely on conformance bugs in IE6 look bad on IE7.  ASP.NET pretends to be standards-conformant, but that really just means “IE6 bug-compatible”.  If you tell ASP.NET to stop pretending, then IE7 says “Oh, this page isn’t really standards-conformant — I’ll render it bug-compatible with older versions of IE”.

So, why does ASP.NET even bother adding that DOCTYPE if it is deceptive?  Well, there are two reasons, neither very satisfying.  The first is that the XHTML political lobby insisted that “XHTML gooood, HTML baaaad”.  So everyone was arm-twisted into emitting XHTML.  The problem is, when the political lobbying started, none of the web browsers actually supported XHTML, they just pretended.  So a server like ASP.NET could choose between emitting code that was XHTML, or emitting code that looked as much like XHTML as possible without breaking Netscape and IE.  Code that looks like XHTML without breaking the browsers is a tiny subset of “actual XHTML”.

Farcial as it may be, it was the best anyone could do, and it got the complainers to stop kvetching.  Now we can all live under the illusion that we support XHTML, even if trivial little changes and isomorphic infosets would break half the world.

The problem is, as soon as you claim to be XHTML, the modern browsers assume that you are also using real CSS.  This goes for Firefox as well as IE.  But IE6 didn’t support CSS properly; so now the GUI web designer tool had two choices:

  1. Emit good CSS, so the code that looks good in Opera but not IE6, and maybe looks good in Firefox
  2. Pretend to be good CSS (by the DOCTYPE), but emit code that looks good on IE6 and hope it works in Firefox or Opera

It’s clear which choice was made.

Enter IE7.  The newest version of IE, like the newest versions of Firefox and Opera, does a much better job of rendering standards-conformant pages.  Suddenly, writing code that looks good only in IE6 seems like a bad idea.  And even if that wasn’t such a bad idea, pretending that it’s standards-conformant sure seems silly.  It just makes our hard work to adopt standards in IE7 look bad.

Well, that’s the story.  Knowing this, you have two choices:

  • Use the legacy design tool and tell ASP.NET to stop pretending that it’s emitting real standards-conformant code.
  • Use more modern design tools (like Expression) and let ASP.NET rightly claim that the code is standards-conformant.

 

7 Responses to “ASP.NET Application Looks Like Hell on IE7?”

  1. Honestas Optima Says:

    There is something missing after this line… “At the top of the .aspx page was the following:” probably the blog engine filtered out your HTML.

    To comment on the post… I am always amazed that a juggernaut like Microsoft does such a good job of keeping all the various programs and components playing together well. For example, I can take an old Turbo Pascal program that I wrote back in 1992 in MS DOS, and it will still run on Windows XP. I was also happy to discover that my ActiveX component for Microsoft Word works on Office 97 and all the way up to Office 2007 with 64 bit Vista.

    Granted, there are glitches now and again, as you just described. But, to contrast, I can never install a linux application the same way twice. Call me bitter, but I just wasted an hour yesterday on an incredibly stupid Cygwin bug, that was carelessly released to the world with a short note in the FAQ.

  2. allenjs Says:

    Insane — Wordpress won’t let me paste in a Doctype no matter how I escape it or encode it. It even strips it if I stick it in CDATA.

  3. scottgu Says:

    ASP.NET doesn’t ever send down a DOCTYPE value – so it isn’t ASP.NET sending it down as part of the page.

    When you create a new ASP.NET page in Visual Studio, though, it will add a DOCTYPE at the top by default to the blank page. With VS 2005, this defaults to indicating XHTML Transitional (which is the same output that ASP.NET controls render with).

    Assuming you add your own code to the page in an XHTML transitional way, then everything work work fine. What I ssupect is happening on the pages referenced above is that the developers has added some non-XHTML compliant markup of their own to the page (and not adjusted the DOCTYPE accordingly). This will then cause issues.

    Hope this helps,

    Scott

  4. scottgu Says:

    Note that to change the DOCTYPE, you just go to the top of the .aspx page and change it like you would with a standard HTML page (it is just standard markup at the top of the page). So if you are developing a non XHTML compliant page, just change the DOCTYPE or remove it entirely.

  5. Jack Says:

    Just to confirm, this actually works. I had spent hours trying to find out why my asp.net2 apps did not display the same way in IE6 and IE7.

    Until I found this hit, i was at my wits end.

    So this does indeed work. Thanks!

  6. Reg Says:

    Thx you soo much final school aspx final depended on this. I am sooo glad I finally I stumbled to your site thank you

    Reggie J

  7. 19 Inches Wide - Kicking them when they are down Says:

    [...] was a huge step in the right direction.) The fixes in IE7 made the applications written using IE6 not work any longer. So instead of realizing it’s their application that needs to upgrade, [...]

Leave a Reply