如何使用服务器端的分隔符时,转义字符 [英] how to escape characters when using server side delimiters

查看:163
本文介绍了如何使用服务器端的分隔符时,转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,目前,一个asp的GridView中,我有以下

So, currently, within an asp gridview, I have the following

<span id="btnEdit" runat="server" onclick="ShowEditCriteriaFilterDialog('<%#Eval("intSMCID")%>', '<%#Eval("strDescription")%>')" class="linkText">Edit</span>

什么,我基本上是寻找的是行情的语法/双引号真正做到这一点的意思,因为上面我所不能正常工作。

What I'm essentially looking for is the syntax for quotes/double-quotes to actually accomplish this properly, as what I have above doesn't properly work.

首先,如果我用单引号封装整个的onclick,并没有投入任何其他引号内的,它适用于渲染的目的,但是当我实际点击在运行时的链接,没有任何反应。

First of all, if i encapsulate the entire onclick with single quotes, and not put any other quotes inside, it works for rendering purposes, but when i actually click the link at runtime, nothing happens.

如果我封装用双引号整个的onclick,像一个ASPX元素的大多数属性,它不能正常显示,而这是第一℃之后逗号后的一切;%#评估和演示%>语句显示为屏幕上的实际文本。这使我相信需要一些转义做prevent它从思想单击处理结束还有某处的那&LT中间;%#%评估和演示>语句

If I encapsulate the entire onclick with double-quotes, like most properties of an ASPX element, it doesn't render properly, and everything after the comma which is after the first <%#Eval %> statement shows up as actual text on the screen. This leads me to believe there needs to be some escaping done to prevent it from thinking the click handler ends somewhere in the middle of that <%#Eval %> statement.

请注意,如果我拿走=服务器,只是它封装在双引号,这似乎更好地工作......但我需要的跨度为其他功能我有很多的服务器端控件在后面,我需要通过的FindControl来访问控件的页的code

note that if I take away runat="server" and just encapsulate it in double-quotes, that seems to work better...but i need the span to be a server-side control for alot of other functionality I have in the page's code behind where I need to access the control through FindControl

推荐答案

评估函数需要双引号,所以你必须包装在单引号的属性值。

The Eval function needs double-quotes, so you have to wrap the attribute value in single quotes.

您不能混用静态内容和&LT;%#......%&GT; 块用于控制一个属性值与 =服务器,所以你需要在构建整个字符串的单个&LT;%#......%&GT;

You can't mix static content and <%# ... %> blocks in a single property value for a control with runat="server", so you need to build the entire string within a single <%# ... %> block.

<击>在一个字符串在&LT;%#......%&GT; 块,你可以使用&放大器;者; 插入一个单引号:结果
修改这只能在.NET 4.0;在2.0中,它生成&放大器;放大器;者; ,这是行不通的。使用双引号来代替:

Within a string in a <%# ... %> block, you can use &apos; to insert a single quote:
EDIT That only works in .NET 4.0; in 2.0, it generates &amp;apos;, which won't work. Use double-quotes instead:

onclick='<%# string.Format(
   "ShowEditCriteriaFilterDialog(\"{0}\", \"{1}\")", 
   Eval("intSMCID"), Eval("strDescription")) %>'

根据您的资料,您可能还需要连接code为JavaScript字符串值:

Depending on your data, you might also need to encode the string value for JavaScript:

onclick='<%# string.Format(
   "ShowEditCriteriaFilterDialog(\"{0}\", \"{1}\")", 
   Eval("intSMCID"), 
   HttpUtility.JavaScriptStringEncode(Eval("strDescription", "{0}"))) %>'

(code为了便于阅读 - 它必须是在一行上)

这篇关于如何使用服务器端的分隔符时,转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆