views:

28

answers:

2

I'm trying to add a Javascript function to the onLoad event of a asp:Panel. It goes something like this:

string clickFunction = "$('[id*=lblHiddenPageArray]').text('');"

PagesPanel.Attribues.Add("onLoad", clickFunction);

I'm attaching this function to other controls (Checkboxes and Buttons) and it's working fine. But in the PagesPanel (my asp:Panel control) it HTMLEncodes the function. The output source looks like this:

onLoad="$('[id*=lblHiddenPageArray]').text('');

I've tried to Server.HTMLDecode it on the assignment, but I get the same thing. I've run into this before in .net 4.0. Surely there's a way to escape the characters or something?

A: 

I'm having the exact same problem. It's driving me crazy. Anyone have a solution?

Sam
A: 

I think that's proper behavior. The attribute values are unencoded by the browser before being executed. A simple example:

<!DOCTYPE html>
<html>
    <head>
        <title>foo</title>
    </head>
    <body onload="alert(&#39;foo&#39);">
        <p>foo</p>
    </body>
</html>

Just in case you for some reason can't un-HTML-encode things in your head ;-), Firebug in Firefox, the WebKit inspector in Safari and Chrome, and Dragonfly in Opera will do it for you automatically.

ngroot