0

Is there a way to show error notification to user when error occurred during partial postback of an Update Panel?

I have tried injecting script using RegisterStartupScript and RegisterClientScriptBlock both, but failed, I believe because partial postback is not successful therefore update panel's internal framework stop executing script, which causes my error notification script to not run. Below is the error I generated on click of a Test button, on click of which enter image description here

Below is the code I'm using to inject error notification alert box for all errors caused during partial postback.

protected void Application_Error(object sender, EventArgs e)  {
    Entities.Exception exceptionObj = new Entities.Exception();
    Exception x = Server.GetLastError();

    if (x != null)  {
        if (x.InnerException != null)  {
            exceptionObj.Message = x.InnerException.Message.ToString();
            exceptionObj.StackTrace = x.InnerException.ToString();
        }  else  {
            exceptionObj.Message = x.Message.ToString();
            exceptionObj.StackTrace = x.ToString();
        }
    }

    Server.ClearError();

    System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
    if (page != null)  {
        RadAjaxManager MainRadAjaxManager = RadAjaxManager.GetCurrent(page);

        if (MainRadAjaxManager != null && MainRadAjaxManager.IsAjaxRequest)
            // didn't work
            //MainRadAjaxManager.ResponseScripts.Add(script); 

            // didn't work
            //page.ClientScript.RegisterStartupScript(page.GetType(), Guid.NewGuid().ToString(), "alert('Yogesh');", true);

            // didn't work
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), Guid.NewGuid().ToString(), "alert('Error Occured.');", true);
    }
}

Note: I'm using Telerik's RadAjaxManager

INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
yogi
  • 19,175
  • 13
  • 62
  • 92
  • 1
    please check this link may be it will help you [UpdatePanel Exception Handling](http://stackoverflow.com/questions/1826008/updatepanel-exception-handling) – Mehul Trivedi Apr 05 '16 at 12:15
  • While the linked thread shows how to capture server exceptions on the client (and that's necessary), this will still not let the server code register your script. Consider attaching a debugger to find where the error originates and handle it so your server logic can continue. – rdmptn Apr 05 '16 at 13:11

0 Answers0