Calling a script from code behind not working..http://forums.asp.net/t/1816588.aspx/1?Calling+a+script+from+code+behind+not+working+Thu, 21 Jun 2012 13:38:13 -040018165885034221http://forums.asp.net/p/1816588/5034221.aspx/1?Calling+a+script+from+code+behind+not+working+Calling a script from code behind not working.. <p>I have some code behind that I am trying to call javascript with on the client side. Everything seems to work fine except when I try and introduce a \n into the messagebox text.&nbsp; I have tried single and double quotes in the script line, but if I put anything in there to do with \n \r environmene.newline or anything it does not fire. I can however place random text and it does work.</p> <pre class="prettyprint">protected void btnGeneratePDF_Click(object sender, EventArgs e) { Page.Validate(&quot;TransValidation&quot;); if (Page.IsValid) { stamp_PDF(true); create_PDF(); } else { string msg = &quot;&quot;; foreach (IValidator aValidator in this.Validators) { if (!aValidator.IsValid) { msg &#43;= aValidator.ErrorMessage &#43; &quot;\n&quot;; //Adding new line for each validator? } } msgBox_error(msg); } } public void msgBox_error(String message) { Label msgBox = new Label(); String msg = message; msgBox.Text = &quot;&lt;&quot; &#43; &quot;script language='javascript'&gt;&quot; &#43; Environment.NewLine &#43; &quot;window.alert(\&quot;&quot; &#43; msg &#43; &quot;\&quot;) &lt;/&quot; &#43; &quot;script&gt;&quot;; Page.Controls.Add(msgBox); }</pre> <p></p> <p>Thoughts?</p> 2012-06-20T17:00:09-04:005034254http://forums.asp.net/p/1816588/5034254.aspx/1?Re+Calling+a+script+from+code+behind+not+working+Re: Calling a script from code behind not working.. <p>When we do a \n or \r, we need&nbsp;to escape it in C# so do that like this:&nbsp;</p> <p>\n =&nbsp;<a href="file://\\n">\\n</a>&nbsp;</p> <p>\r =&nbsp;<a href="file://\\r">\\r</a></p> 2012-06-20T17:35:12-04:005034308http://forums.asp.net/p/1816588/5034308.aspx/1?Re+Calling+a+script+from+code+behind+not+working+Re: Calling a script from code behind not working.. <p>Thank you, I had thought the \ was the escape, but i guess that is part of the character.</p> 2012-06-20T18:23:09-04:005035436http://forums.asp.net/p/1816588/5035436.aspx/1?Re+Calling+a+script+from+code+behind+not+working+Re: Calling a script from code behind not working.. <p>Correct :)</p> 2012-06-21T13:38:13-04:00