在 asp.net Onclick 字符串中转义双引号

发布于 2024-09-08 22:49:49 字数 201 浏览 4 评论 0原文

我试图将动态数据插入到控件的 onclick 属性中,代码看起来像这样,

onclick="openRadWindow('<%#Eval("ID";) %>','<%#Eval("ParentObjectID") %>');"

我无法让它触发,问题似乎是双引号,转义引号以便触发的正确方法是什么。

I am trying to insert dynamic data into a onclick property for a control the code looks like this

onclick="openRadWindow('<%#Eval("ID";) %>','<%#Eval("ParentObjectID") %>');"

I cant get it to fire and the trouble seems to be the double quotes, what is the correct method on escaping the quotes so that this fires.

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

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

发布评论

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

评论(4

彼岸花似海 2024-09-15 22:49:49

您可以使用格式字符串,如下所示:

onclick='<%# string.Format("openRadWindow(\"{0}, {1}\");", Eval("ID"), Eval("ParentObjectID")) %>' 

You can do use a format string, like this:

onclick='<%# string.Format("openRadWindow(\"{0}, {1}\");", Eval("ID"), Eval("ParentObjectID")) %>' 
記憶穿過時間隧道 2024-09-15 22:49:49

是事件没有触发还是您也收到任何 javascript 错误。另外,我会在页面呈现后查看 HTML,并确保服务器标记得到正确处理。某些用途会导致它们实际上未被处理,并且将保留为 <%# Eval("ID") %>。

Is the event just not firing or are you getting any javascript errors as well. Also, I would look at the HTML after the page has been rendered and make sure that the server tags are being processed correctly. There are certain uses that cause them not to actually be processed and will remain <%# Eval("ID") %>.

海风掠过北极光 2024-09-15 22:49:49

感谢大家,我能够使用不同的方法使其正常工作。在后面的代码中,我创建了一个函数,在函数中添加了以下代码

Return String.Format("openRadWindow({0},{1});", photo.ID, photo.ParentObjectID)

,并在 aspx 中添加了 onclick="<%#MyFunction(DirectCast(Container.DataItem,Photo))%>

Thanks to all I was able to get it working correctly using a different method. in the code behind I created a function and in the function I put the following code

Return String.Format("openRadWindow({0},{1});", photo.ID, photo.ParentObjectID)

and in the aspx I added onclick="<%#MyFunction(DirectCast(Container.DataItem,Photo))%>

那伤。 2024-09-15 22:49:49

我首先看到的是“ID”后面的分号 - 我认为这可能会导致您的问题。

First thing I see is that semi-colon after "ID" - I think that might be causing your problems.

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