Ajax Callback Error in ASP.NET Part 2 – Client Side Popup

A new event was added to all of our ASP.NET controls that use callbacks. The CallbackError event handler is a client-side event and can be used to handle those pesky callback errors. This event captures and displays callback errors using the client-side JavaScript. The event still require the use of an ASPxHttpHandler module, which is responsible for intercepting the callback error. However, this event now gives you the choice of displaying the error on the client side.

To use it, override the event using the smart tag of the control or you can add the event code using source HTML view. Here is an example that shows how the ASPxGridView will use a JavaScript alert popup to display the error message:

<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
CssFilePath="~/App_Themes/Plastic Blue/{0}/styles.css" CssPostfix="PlasticBlue"
DataSourceID="SqlDataSource1">
<ClientSideEvents
CallbackError="function(s, e) {
alert(e.message);
e.handled = true;
}" />

With this new event, there are now three different way to handle and respond to callback errors:

  1. Server side – Respond to the control
  2. Server side – Redirect to a general error page
  3. Client side

Which method do you prefer to respond to callback errors with?

5 comment(s)

Nice post. I was looking for one like this to handle database posting errors in Oracle using XPO and communicate it effectively to the user. I am a novice to your controls.  Would you publish a cheat sheet on the Events, Properties (there are just too many of them to comprehend and use it effectively)

2 August, 2008
Kamran Shahid

What I need is Stack Trace with the error Message.

Is it possible to Get Stack Trace or not ?

4 August, 2008

Hi Kamran,

For now it's impossible. We only send the error message to the client-side.

A couple weeks ago, a customer wanted to send a custom error message to the client-side. So we've added a suggestion about it and I recommend tracking it: www.devexpress.com/issue=S30328

4 August, 2008

Hi Shankar,

Check out part 1 to this post which has a screencast that shows how to redirect to a general error page. However, for posting errors, you may want to either use debug or log them somewhere because callbacks are not the best place to catch them. Here is the screencast: community.devexpress.com/.../video-how-to-handle-an-asp-net-ajax-callback-error.aspx

4 August, 2008

But how we can alert database errors? Suppose in callback i use method which works with database and there is database error message. How i can show it on client side via alert message?

24 September, 2012

Please login or register to post comments.