在 4.0 中向 ASP.NET 控件添加客户端 onload 函数对我的报价进行编码

发布于 2024-09-08 05:10:32 字数 491 浏览 1 评论 0原文

我正在尝试将 Javascript 函数添加到 asp:Panel 的 onLoad 事件中。它是这样的:

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

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

我将此函数附加到其他控件(复选框和按钮)并且它工作正常。但在 PagesPanel(我的 asp:Panel 控件)中,它对函数进行 HTMLEncodes。输出源如下所示:

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

我尝试在作业中对其进行 Server.HTMLDecode,但得到了同样的结果。我之前在 .net 4.0 中遇到过这个问题。肯定有办法逃脱角色之类的吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的巷 2024-09-15 05:10:32

我认为这是正确的行为。属性值在执行之前不会被浏览器编码。一个简单的例子:

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

以防万一您由于某种原因无法在头脑中取消 HTML 编码;-),Firefox 中的 Firebug、Safari 和 Chrome 中的 WebKit 检查器以及 Opera 中的 Dragonfly 会自动为您完成此操作。

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('foo');">
        <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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文