Thursday, March 29, 2007

Ajax extensions services always report “There was an error processing the request.”

I have been puzzled by the following for quite a while.

I use Microsoft Ajax extensions 1.0 to query web services which may raise exceptions. In my development environment, I would always get a nice localized error message but on the production server, the same code would produce a generic “There was an error processing the request”.

After having spent enough time stepping through my code with a debugger, I have decided to look at the Ajax extensions code and I have found the following piece of code in WriteExceptionJsonString of RestHandler.cs.

if (context.IsCustomErrorEnabled)
writer.Write(JavaScriptSerializer.SerializeInternal(new WebServiceError(

AtlasWeb.WebService_Error, String.Empty, String.Empty)));
writer.Write(JavaScriptSerializer.SerializeInternal(new WebServiceError(

ex.Message, ex.StackTrace, ex.GetType().FullName)));

Where WebService_Error is a resource which is valued “There was an error processing the request.”

This means that if you have enabled custom errors in your web.config on your production environment like I did, your Ajax calls will always report a generic error.

Why have the Microsoft people introduced such a restriction is a mystery to me.

Friday, March 16, 2007

Extender controls may not be registered before PreRender

Today, I have added new AjaxControlToolkit controls to Velodoc pages and I got exception “Extender controls may not be registered before PreRender” from running a page.

All our pages derive from our own WebPage class which derive from the standard Page class. WebPage provides features like custom error handling and QueryString parsing into page properties.

The page where we had the new extender control had the following method:

protected override void OnPreRender(EventArgs e)
//The following line is required, otherwise you get "Extender controls
//may not be registered before PreRender."

//Some code that displays errors on postbacks

The solution to the problem above is to add base.OnPreRender(e); at the beginning of the method.