views:

128

answers:

1

this displays the expected javascript alert message box:

RadAjaxManager1.ResponseScripts.Add("alert('blahblahblah');");

while these does not:

RadAjaxManager1.ResponseScripts.Add("alert('blahblah \n blahblahblah');");
RadAjaxManager1.ResponseScripts.Add("alert('blahblah \r blahblahblah');");
RadAjaxManager1.ResponseScripts.Add("alert('blahblah \r\n blahblahblah');");
RadAjaxManager1.ResponseScripts.Add("alert('blahblah \n\t blahblahblah');");
RadAjaxManager1.ResponseScripts.Add(@"alert('blahblah \n blahblahblah');");
string message = "blahblahblah \n blahblahblah";
RadAjaxManager1.ResponseScripts.Add(message);

I can't find any documentation on escape characters breaking this. I understand the single string argument to the Add method can be any script. No error is thrown, so my best guess is malformed javascript.

+1  A: 

The \n you add in the string is actually parsed in .NET as a new line and so it arrives at the client as such. For example:

setTimeout(function(){alert('blahblah 
blahblahblah');}, 0);

The above is not valid JavaScript code and will not execute. In order to have an actual \n in the client script, you must escape it in the server code as \n. For example:

RadAjaxManager1.ResponseScripts.Add("alert('blahblah \\n blahblahblah');");

will output:

setTimeout(function(){alert('blahblah \n blahblahblah');}, 0);
lingvomir
does \\t break something else? I tried "blah\\n\\tblah\\nblah" and the "nt" group displayed as \n\t while the second \\n was correct.
David
"blah\\n\\tblah\\nblah" works correctly for me (using Q1 2010 version). I see blah blahblah
lingvomir