Why do escape characters break my Telerik call to ResponseScripts.Add(string)?
this displays the expected javascript alert message box:
RadAjaxManager1.ResponseScripts.Add("alert('blahblahblah');");
while these does not:
RadAjaxManager1.ResponseScripts.Add("alert('blahblah \n bl开发者_如何转开发ahblahblah');");
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.
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);
精彩评论