Back to Devexpress

ASPxWebControl.CallbackError Event

aspnet-devexpress-dot-web-dot-aspxwebcontrol-9ea604f2.md

latest18.2 KB
Original Source

ASPxWebControl.CallbackError Event

Allows you to handle any server exception that might occur during server-side processing of a callback sent by a DevExpress web control.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public static event EventHandler CallbackError
vb
Public Shared Event CallbackError As EventHandler

Event Data

The CallbackError event's data class is EventArgs.

Remarks

See Handling Callback Exceptions on the Server Side to learn more.

View Example: How to handle application-level errors occurred during callbacks

Example

This example demonstrates how the ASPxWebControl.CallbackError server static event can be used within the Global.asax file to delegate handling of exceptions that occur during processing of DevExpress web control callbacks to the Application_Error event handler.

View Example

aspx
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="DevExpress.Web" %>

<script RunAt="server">
    void Application_Start(object sender, EventArgs e) {
        // Assign Application_Error as a callback error handler
        ASPxWebControl.CallbackError += new EventHandler(Application_Error);
    }

    void Application_Error(object sender, EventArgs e) {
        // Use HttpContext.Current to get a Web request processing helper
        HttpServerUtility server = HttpContext.Current.Server;
        Exception exception = server.GetLastError();
        if (exception is HttpUnhandledException)
            exception = exception.InnerException;
        // Log an exception
        AddToLog(exception.Message, exception.StackTrace);
    }

    void AddToLog(string message, string stackTrace) {
        StringBuilder sb = new StringBuilder();
        sb.AppendLine(DateTime.Now.ToLocalTime().ToString());
        sb.AppendLine(message);
        sb.AppendLine();
        sb.AppendLine("Source File: " + HttpContext.Current.Request.RawUrl);
        sb.AppendLine();
        sb.AppendLine("Stack Trace: ");
        sb.AppendLine(stackTrace);
        for (int i = 0; i < 150; i++)
            sb.Append("-");
        sb.AppendLine();
        HttpContext.Current.Session["Log"] += sb.ToString();
        sb.AppendLine();
    }
</script>
aspx
<%@ Application Language="vb" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="DevExpress.Web" %>

<script RunAt="server">
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Assign Application_Error as a callback error handler
        AddHandler ASPxWebControl.CallbackError, AddressOf Application_Error
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Use HttpContext.Current to get a Web request processing helper
        Dim exception As Exception = HttpContext.Current.Server.GetLastError()
        If TypeOf exception Is HttpUnhandledException Then
            exception = exception.InnerException
        End If
        ' Log an exception
        AddToLog(exception.Message, exception.StackTrace)
    End Sub

    Sub AddToLog(ByVal message As String, ByVal stackTrace As String)
        Dim sb As New StringBuilder()
        sb.AppendLine(Date.Now.ToLocalTime().ToString())
        sb.AppendLine(message)
        sb.AppendLine()
        sb.AppendLine("Source File: " & HttpContext.Current.Request.RawUrl)
        sb.AppendLine()
        sb.AppendLine("Stack Trace: ")
        sb.AppendLine(stackTrace)
        For i As Integer = 0 To 149
            sb.Append("-")
        Next i
        sb.AppendLine()
        HttpContext.Current.Session("Log") += sb.ToString()
        sb.AppendLine()
    End Sub
</script>
aspx
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="devExpress">
      <section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
    </sectionGroup>
  </configSections>
  
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="DevExpress.Data.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Printing.v15.1.Core, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="DevExpress.RichEdit.v15.1.Core, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
      </assemblies>
    </compilation>
    <pages validateRequest="false"></pages>
    <customErrors redirectMode="ResponseRedirect" defaultRedirect="~/ErrorPage.aspx" mode="On">
      <error statusCode="500" redirect="~/ErrorPage.aspx" />
    </customErrors>
    <httpModules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </httpModules>
    <httpHandlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" validate="false" />
      <add verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
    </httpHandlers>
  
  
    <modules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
      <add name="ASPxUploadProgressHandler" preCondition="integratedMode" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
    </handlers>
  
  <devExpress>
    <themes enableThemesAssembly="true" styleSheetTheme="" theme="" customThemeAssemblies="" />
    <compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true" />
    <settings doctypeMode="Xhtml" rightToLeft="false" embedRequiredClientLibraries="false" ieCompatibilityVersion="edge" />
    <errors callbackErrorRedirectUrl="~/ErrorPage.aspx" />
  </devExpress>
</configuration>
aspx
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="devExpress">
      <section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
    </sectionGroup>
  </configSections>
  
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="DevExpress.Data.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Printing.v15.1.Core, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="DevExpress.RichEdit.v15.1.Core, Version=15.1.15.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
      </assemblies>
    </compilation>
    <pages validateRequest="false"></pages>
    <customErrors redirectMode="ResponseRedirect" defaultRedirect="~/ErrorPage.aspx" mode="On">
      <error statusCode="500" redirect="~/ErrorPage.aspx" />
    </customErrors>
    <httpModules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </httpModules>
    <httpHandlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" validate="false" />
      <add verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
    </httpHandlers>
  
  
    <modules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
      <add name="ASPxUploadProgressHandler" preCondition="integratedMode" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
    </handlers>
  
  <devExpress>
    <themes enableThemesAssembly="true" styleSheetTheme="" theme="" customThemeAssemblies="" />
    <compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true" />
    <settings doctypeMode="Xhtml" rightToLeft="false" embedRequiredClientLibraries="false" ieCompatibilityVersion="edge" />
    <errors callbackErrorRedirectUrl="~/ErrorPage.aspx" />
  </devExpress>
</configuration>

The following code snippets (auto-collected from DevExpress Examples) contain references to the CallbackError event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

web-forms-dashboard-handle-errors/CS/WebFormsThrowCustomExceptionDashboardErrorToast/WebForm1.aspx.cs#L11

csharp
static WebForm1() {
    ASPxWebControl.CallbackError += ASPxWebControl_CallbackError;
}

javascript-dashboard-localization/CS/DashboardLocalizationManualHTMLJS/Global.asax.cs#L25

csharp
DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
}

reporting-web-customize-web-report-wizard/CS/WebFormsWizardCustomization/Global.asax.cs#L18

csharp
DevExpress.Web.ASPxWebControl.CallbackError += new EventHandler(Application_Error);
}

dashboard-constant-lines/CS/WebDashboardSample/Global.asax.cs#L12

csharp
void Application_Start(object sender, EventArgs e) {
    DevExpress.Web.ASPxWebControl.CallbackError += new EventHandler(Application_Error);
    string commonDataDirectory = Directory.GetParent(Directory.GetParent(HostingEnvironment.MapPath("~")).FullName).FullName;

asp-net-mvc-dashboard-localization/CS/DashboardLocalizationMVC/Global.asax.cs#L25

csharp
ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
    DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
}

web-forms-dashboard-handle-errors/VB/WebFormsThrowCustomExceptionDashboardErrorToast/WebForm1.aspx.vb#L14

vb
Shared Sub New()
    AddHandler ASPxWebControl.CallbackError, AddressOf ASPxWebControl_CallbackError
End Sub

xaf-how-to-use-data-from-security-in-criterion/VB/CustomFunctionCriteriaOperator.Web/Global.asax.vb#L24

vb
DevExpress.ExpressApp.FrameworkSettings.DefaultSettingsCompatibilityMode = DevExpress.ExpressApp.FrameworkSettingsCompatibilityMode.v20_1
AddHandler ASPxWebControl.CallbackError, AddressOf Application_Error

asp-net-mvc-scheduler-crud-operations/VB/MVCSchedulerEditable/Global.asax.vb#L17

vb
ModelBinders.Binders.DefaultBinder = New DevExpress.Web.Mvc.DevExpressEditorsBinder()
    AddHandler DevExpress.Web.ASPxWebControl.CallbackError, AddressOf Application_Error
End Sub

xaf-how-to-dynamically-change-mask-settings-based-on-the-current-object/VB/ChangeEditMask.Web/Global.asax.vb#L18

vb
DevExpress.ExpressApp.FrameworkSettings.DefaultSettingsCompatibilityMode = DevExpress.ExpressApp.FrameworkSettingsCompatibilityMode.v20_1
AddHandler ASPxWebControl.CallbackError, New EventHandler(AddressOf Application_Error)
#If EASYTEST

xaf-how-to-use-the-file-attachment-module-with-a-legacy-database/VB/CustomFileDataSolution.Web/Global.asax.vb#L22

vb
DevExpress.ExpressApp.FrameworkSettings.DefaultSettingsCompatibilityMode = DevExpress.ExpressApp.FrameworkSettingsCompatibilityMode.v20_1
AddHandler ASPxWebControl.CallbackError, AddressOf Application_Error
#If EASYTEST Then

See Also

Code Central Example - E2398 (How to handle callback event errors using the ASPxWebControl.CallbackError event)

CallbackError

Handle Callback Exceptions

Callbacks

ASPxWebControl Class

ASPxWebControl Members

DevExpress.Web Namespace