Skip to main content
A newer version of this page is available. .

Displaying Message Text for Callback Errors

  • 3 minutes to read

If an unhandled exception occurs while a DevExpress web control’s callback is processed on the server side, ASPxHttpHandlerModule automatically catches the exception and passes an error message to the client. This message may contain details about the exception or a generic error message. The message displayed depends on the mode attribute setting within the Web.config file’s <customErrors> section. This attribute affects message text in the following manner.

  • On - Generic (custom) error text is shown to remote clients and to the local host. This text can be localized, and is defined by the ASPxperienceStringId.CallbackGenericErrorText constant.
  • Off - Detailed ASP.NET errors are shown to remote clients and to the local host.
  • RemoteOnly - Generic (custom) error text is shown only to remote clients, and detailed ASP.NET errors are displayed on the local host.

Note

This behavior was introduced in v14.2 to improve security and avoid exposing a callback’s full error text, which might contain private information.

Regardless of the customErrors mode setting, you can use one of the following approaches to modify the error message to be sent to the client.

  • Handle a DevExpress control’s CustomErrorText event, if any. Some DevExpress web controls (such as ASPxGridView.CustomErrorText and ASPxTreeList.CustomErrorText) provide this event.

    In the event handler, use the e.ErrorText property to define error text. Note that the initial value passed to this event depends on the customErrors mode setting. Within the event, you can access the source error (and its error message) via the e.Exception property.

    //Generate your own exception type
    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {        
        throw new CustomExceptions.MyException("Editing is disabled. Please log in as administrator.");
    }
    
    //Change error text for your exception type
    protected void ASPxGridView1_CustomErrorText(object sender, DevExpress.Web.ASPxGridViewCustomErrorTextEventArgs e) {        
        if(e.Exception is CustomExceptions.MyException) {
            e.ErrorText = e.Exception.Message;
        }
    }
    
  • Alternatively, you can use the static ASPxWebControl.SetCallbackErrorMessage method.

    Call this method in the Application_Error and ASPxWebControl.CallbackError event handlers in Global.asax. Within these handlers, use the HttpContext.Current.Server.GetLastError method to access the source error.

    //Generate your own exception type
    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {        
        throw new CustomExceptions.MyException("Editing is disabled. Please log in as administrator.");
    }
    
    //Change error text in CallbackError event handler using the SetCallbackErrorMessage method 
        void Application_Start(object sender, EventArgs e){
            DevExpress.Web.ASPxWebControl.CallbackError += Callback_Error;
        }
        protected void Callback_Error(object sender, EventArgs e) {
            var exception = HttpContext.Current.Server.GetLastError();
            //Check exception type and specify error text for your exception
            if(exception is CustomExceptions.MyException) {
                DevExpress.Web.ASPxWebControl.SetCallbackErrorMessage(exception.Message);
            }
        }
    

Online Examples