Question

Working with a legacy asp.net web app, is there a way to add conditional comments around two <html> tags, while still maintaining runat="server" attributes? (Server side browser detection, re-writing the rendered control, and client side css class additions aren't options). The following does not work...

<!--[if lt IE 9]>
     <html class="old-ie" runat="server">
<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
     <html runat="server">
<!--<![endif]-->

this doesn't work either...

 <html runat="server" <!--[if lt IE 9]>class="old-ie"<![endif]-->>

An exception will be thrown in both cases.

Was it helpful?

Solution 2

In the end, I decided to just use conditional comments around a stylesheet, rather than trying to decorate the <html> tag with IE-specific css classes.

OTHER TIPS

You're going to need to determine the class to output in the code behind and then either output that HTML or append that attribute.

Remember that these conditional comments are always in the generated HTML. In the first scenario you have two HTML tags with runat attributes which is invalid, hence the error. (Actually just two HTML tags without runat attributes would be invalid, too, but probably would result in a parser error.) In the second one, you have a comment crammed into the middle of the HTML tag which is generating the error.

You could do something like this:

<html runat="server" id="HtmlTag" />

and then in the codebehind

HtmlTag.CssClass = "old-ie";

(That's untested, but you get the idea)

This will allow you to manage the code a little easier, have cleaner HTML outputs, and theoretically faster page load times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top