The problem is that
ex.Message
may contain multiple line breaks which will foul up your javascript. What you should do is post the part you're interested in after it was rendered to your browser. Look at the page source for that and locate the script tag you've generated. You can also try to store the exception message inside a DIV tag and then read that from your javascript code:
catch (Exception ex)
{
Response.Write("<div id='exceptionDiv'>" + ex.Message + "</div>";
Response.Write("<script>alert(document.getElementById('exceptionDiv').innerHTML)</script>");
}
Regards,
—MRB