WebDocumentViewerClientSideEventsBuilder.OnServerError(String) Method

Specifies the JavaScript function that handles the client-side OnServerError event.

Namespace: DevExpress.AspNetCore.Reporting.WebDocumentViewer

Assembly: DevExpress.AspNetCore.Reporting.v21.1.dll

Declaration

public WebDocumentViewerClientSideEventsBuilder OnServerError(
    string callback
)

Parameters

Name Type Description
callback String

The name of a JavaScript function or entire JavaScript function code that runs when the OnServerError event occurs.

Returns

Type Description
WebDocumentViewerClientSideEventsBuilder

A WebDocumentViewerClientSideEventsBuilder that can be used for method chaining.

Remarks

The client-side OnServerError event is raised when a server-side error occurs. Handle this event to execute custom code when an Ajax request completes with an error.

The handler function receives two parameters. The first parameter is the client-side DocumentViewer that exposes the IPreviewModel interface (or the JSReportViewer object). The second is an object with the Error property, which contains information about an error:

The following code snippet logs error details and displays an alert box when a server error occurs:

<script type="text/javascript" id="script">
    function onServerError(s,e) {
        console.log(JSON.stringify(e.Error.getRequestDetails()));
        console.log(e.Error.errorThrown);
        let actionKey = e.Error.getRequestDetails().actionKey;
        let error = e.Error.errorThrown;
        alert("Server error" + "\r\nAction: " + actionKey + "\r\nMessage: " + error);
    }
</script>

@{
    var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")
        .Height("1000px")
        .ClientSideEvents(configure => configure.OnServerError("onServerError"))
        .Bind("TestReport");
    @viewerRender.RenderHtml()
} 
See Also