364,083 Members | 5476 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Eval and Apostrophe

infodemers
P: 1
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
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 2.5K+
P: 4,631
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

Help answer this question



Didn't find the answer to your JavaScript / Ajax / DHTML question?

You can also browse similar questions: JavaScript / Ajax / DHTML