在 asp.net Onclick 字符串中转义双引号
我试图将动态数据插入到控件的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用格式字符串,如下所示:
You can do use a format string, like this:
是事件没有触发还是您也收到任何 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") %>.
感谢大家,我能够使用不同的方法使其正常工作。在后面的代码中,我创建了一个函数,在函数中添加了以下代码
,并在 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
and in the aspx I added
onclick="<%#MyFunction(DirectCast(Container.DataItem,Photo))%>
我首先看到的是“ID”后面的分号 - 我认为这可能会导致您的问题。
First thing I see is that semi-colon after "ID" - I think that might be causing your problems.