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

Displaying Message Texts for Callback Errors

  • 3 minutes to read

If an unhandled exception occurs while a DevExpress web control callback is processed on the server side, the 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 <customErrors> section in Web.config, which affects message text in the following manner.

  • On - A generic (custom) error text is shown for remote clients and to the local host. This is localizable text 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 version 2014 vol.2 to improve security and avoid exposing the full error text of a callback error, 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. The source error (and its error message) can be accessed within the event using 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.

    This method can be called in handlers of the Application_Error and ASPxWebControl.CallbackError events in Global.asax. In 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