469,579 Members | 1,188 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Eval and Apostrophe

Hi everyone,

I have the following code:
Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField>
  2.                                             <ItemTemplate>
  3.                                                 <a href="javascript:openPopup('Info.aspx?id=<%# Eval("strresultats") %>')">
  4.                                                     <img alt='<%# Eval("strresultats") %>' src="Info.png" style="border: 0px; width: 32px;" /></a>
  5.                                             </ItemTemplate>
  6.                                         </asp:TemplateField>
For some reason, whenever there is an apostrophe into the strresultats variable, this won't work, Any idea ?

Thanks for your help!
Sep 24 '07 #1
1 3196
5,390 Expert Mod 4TB
hi ...

this is desired behaviour of javascript ... have a look at the following example, that works th normal way:

Expand|Select|Wrap|Line Numbers
  1. eval('alert("test")');
now we put a single quote in:

Expand|Select|Wrap|Line Numbers
  1. eval('alert("te'st")');
it will not work ... why? the single quote terminates the code after:

Expand|Select|Wrap|Line Numbers
  1. eval('alert("te'
so it cannot work. it is the same in your case ... the js-statement would be terminated with the single-quote in your result-string ... you may resolve it with:

Expand|Select|Wrap|Line Numbers
  1. eval('alert("te\'st")');
that means you have to escape the quote here ... and it is working again.

kind regards
Sep 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Meyer1228 | last post: by
2 posts views Thread by Michael Sterling | last post: by
1 post views Thread by spacehopper_man | last post: by
1 post views Thread by Rose | last post: by
9 posts views Thread by Thomas 'PointedEars' Lahn | last post: by
4 posts views Thread by Razzbar | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.