Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aleko - 10 Dec 2007 21:49 GMT
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
Scott M. - 10 Dec 2007 22:28 GMT
try the server.htmldecode() method.

> Hi,
>
[quoted text clipped - 23 lines]
>
> Aleko
bruce barker - 11 Dec 2007 17:25 GMT
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)

> Hi,
>
[quoted text clipped - 23 lines]
>
> Aleko
aleko - 14 Dec 2007 21:59 GMT
On Dec 11, 9:25 am, bruce barker
<brucebar...@discussions.microsoft.com> wrote:
> 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.
[quoted text clipped - 28 lines]
>
> > Aleko

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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.