Hi,
ken s wrote:
From server-side code I'm using Response.Write to display a javascript alert
box. It works fine except when I try to include a new line character, which
causes this javascript error:
"Unterminated string constant"
Here's my c# code:
strText = "Line 1 text\nLine2 text";
Response.Write("<script>alert('" + strText + "');</script>");
Any ideas how to get around this problem?
Make a view-source on the produced HTML code. You will see this:
<script>alert('Line 1 text
Line2 text');</script>
This is illegal JavaScript. Unlike HTML, JavaScript strings cannot be
spread one more than one line without being closed.
What you want is this:
<script>alert('Line 1 text\nLine 2 text');</script>
which in the code behind translates to:
Response.Write( "<script>alert('Line 1 text\\nLine 2 text');</script>" );
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch