Browser not handling exception from AJAX panel, ASP.NET c#

Posted by Grant on Stack Overflow See other posts from Stack Overflow or by Grant
Published on 2010-05-27T00:00:04Z Indexed on 2010/05/27 0:11 UTC
Read the original article Hit count: 197

Filed under:
|
|
|
|

Hi, i am having trouble catching errors in an AJAX panel. Even when i throw an exception in the c# code behind the front end completely ignores it.

Here is the code i have setup, can anyone see why?

I ideally want to show a js alert window on error.

Code Behind:

protected void btnX_Click(object sender, EventArgs e)
{
    throw new ApplicationException("test");
}

protected void ScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
    ScriptManager.AsyncPostBackErrorMessage = e.Exception.Message;
}

Markup:

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function EndRequestHandler(sender, e)
    {
       window.alert(e.get_error().name);
    }
</script>

<asp:ScriptManager ID="ScriptManager" runat="server" AllowCustomErrorsRedirect="true" OnAsyncPostBackError="ScriptManager_AsyncPostBackError" />

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET