Argh: Style.Add() HTML-encodes the value

A

aleko

Hi,

I am writing a server control, and I need a MinWidth property. Since
the min-width CSS style is not (properly) supported by IE, I am using
an expression, like so:

if (HttpContext.Current.Request.Browser.Browser.Contains("IE"))
{
table.Style.Add("width", "expression(document.body.clientWidth < " +
MinWidth.Value + " ? \"" + MinWidth.ToString() + "\" : \"auto\")");
}
else
{
table.Style.Add("width", "100%");
table.Style.Add("min-width", MinWidth.ToString());
}

The problem is that the outputted style HTML-encodes the style value:

style="width:expression(document.body.clientWidth &lt; 960 ? &quot;
960px&quot; : &quot;auto&quot;);"

Is there a way to prevent the style from being encoded?

Thanks,

Aleko
 
B

bruce barker

no fix is required. there is nothing wrong with html encoding javascript
inside an attribute value, as the browser will decode before doing an eval.

-- bruce (sqlwork.com)
 
A

aleko

no fix is required. there is nothing wrong with html encoding javascript
inside an attribute value, as the browser will decode before doing an eval.

-- bruce (sqlwork.com)

Bruce, you're right! I made a little test page with encoded, and
unencoded styles and it worked in both IE6 and 7. Strange why it
doesn't work in the full web page, but that's another problem.

Scott, I tried decoding the style, tried inserting various character
codes, but the end result is always encoded the same way.

Thanks guys!

BTW, the CSS solution works in IE6 ONLY if the page is in quirks mode.
If you add a doctype, and start sizing the window down the browser
just hangs when the width reaches the expression threshold.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top