Display exception message using JavaScript in Base Page's OnError event
<p>I want to display all unhandled excpetions in the appplication using Javascript. For this I have defined onError event inside my custom base class of my pages. Here is the code for my Base Page:</p>

<pre><code>namespace Loan
{

  public class BasePage : System.Web.UI.Page
  {
        public BasePage()
        {

        }

    protected override void OnError(EventArgs e)
    {
        //Report Error
        Exception ex = Server.GetLastError();

        if (ex is HttpUnhandledException &amp;&amp; ex.InnerException != null)
        {
            ex = ex.InnerException;
        }

        var _message = "Error : "+ ex.Message.ToString();

        DisplayAlert(_message);

        Server.ClearError();
        return;
    }

    protected virtual void DisplayAlert(string message)
    {
        ClientScript.RegisterStartupScript(
                        this.GetType(),
                        Guid.NewGuid().ToString(),
                        string.Format("alert('{0}');", message.Replace("'", @"\'")),
                        true
                    );
    }
  }
}
</code></pre>

<p>The alert is never displayed for an unhandled exception. However, if I call the DisplayAlert from any Page  </p>

<pre><code>base.DisplayAlert(ex.Message);
</code></pre>

<p>the javascript alert is displayed. How can I get the javascript alert to be displayed for the unhandled exceptions from the base page.Or is there any other way to display these exception messages to the user. I don't want to redirect them to a generic error page as it sends them back and forth.</p>
