I have RegisterStartupScript in the code-behind class to alert error message -- it works fine except when the error has line feeds or carriage returns (I think). Here is the snippet:
The commented code works fine!
catch (Exception ex)
{
//Page.ClientScript.ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Failure", "alert('ERROR: '), true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "System Error", "alert('" + ex.Message.Replace("'", "\\'") + "');", true);
}
Line terminators are not allowed in js strings. Eliminate the line terminators (carriage returns, new line symbols etc.) using regular expressions: