Handling Callback Exceptions on the Client Side

  • 2 minutes to read

A DevExpress ASP.NET Ajax-enabled control automatically catches server exceptions that occur within its server-side event handler, and passes corresponding error information to the client for processing. On the client side, use the control's CallbackError client event to process the error at the control level, or handle the ASPxGlobalEvents control's ASPxClientGlobalEvents.CallbackError client event to process the error globally (across all DevExpress web controls).

Handle either of these client events to perform specific client-side actions, such as to display explanatory text or an image related to the error.

Example

This example demonstrates how to use the ASPxClientNavBar.CallbackError event to process a server error.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 
Inherits="_Default" %>
<%@ Register assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, 
PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxNavBar" tagprefix="dxnb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e){
    }
    protected void ASPxNavBar1_ExpandedChanged(object source, 
      DevExpress.Web.NavBarGroupEventArgs e) {
        throw new Exception("A new exception.");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <dxnb:ASPxNavBar ID="ASPxNavBar1" runat="server" AutoCollapse="True" 
            EnableCallBacks="True" onexpandedchanged="ASPxNavBar1_ExpandedChanged" 
            Width="252px">
            <Groups>
                <dxnb:NavBarGroup Text="Products">
                    <Items>
                        <dxnb:NavBarItem Text="ASP.NET Components">
                        </dxnb:NavBarItem>
                        <dxnb:NavBarItem Text=".NET WinForms Components">
                        </dxnb:NavBarItem>
                        <dxnb:NavBarItem Text="VCL Components">
                        </dxnb:NavBarItem>
                    </Items>
                </dxnb:NavBarGroup>
                <dxnb:NavBarGroup Expanded="False" Text="Support">
                    <Items>
                        <dxnb:NavBarItem Text="Client Center">
                        </dxnb:NavBarItem>
                        <dxnb:NavBarItem Text="Online Help">
                        </dxnb:NavBarItem>
                        <dxnb:NavBarItem Text="Contacts">
                        </dxnb:NavBarItem>
                    </Items>
                </dxnb:NavBarGroup>
            </Groups>
            <ClientSideEvents CallbackError="function(s, e) {
        if (e.message=='A new exception.') {
        alert('The CallbackError event is raised!'); }
            }" />
        </dxnb:ASPxNavBar>

    </div>
    </form>
</body>
</html>