In light of the rising popularity of AJAX during the last couple of years, Microsoft wanted to include the feature natively into ASP.NET’s object model. They came up with an elegant solution for the feature in ASP.NET 2.0 and they called it Client-Callback.

The elegance of Client-Callback

The elegance of Client-Callback is strongly tied with the simple implementation on aspx web pages. You only need to implement the ICallbackEventHandler interface and add two methods, one method for doing the work and one for sending the response back to the caller. This allows you to execute the two methods asynchronous if you choose. The elegance of the code-behind implementation is only enhanced by the client-side JavaScript code you need in order to call the Client-Callback method. It’s literally only one line of JavaScript code to call it, and one function to receive the response.

What all this means is that it is very easy to start using, because you get all these features out of the box. You still have to write all the logic your self, both the server-side and client-side which can be trickier if you’re not a somewhat experienced JavaScript scripter. But if you are, then you can do magic in a fast and simple way using ASP.NET Client-Callback.

The lack of performance

All of this great functionality comes with a price, and that price is performance. The time between the request and the response is the measure of performance of this feature, and it’s actually not bad for single requests. The slow performance occurs when you do multiple calls on the same page.

Let’s say you have a table of 25 products and when the mouse hovers over the name, an image of that product is displayed right next to the cursor. It’s a nice feature and the website visitors find it useful and try hovering over multiple products in a relative short period of time. The first image is loaded pretty fast, but the rest hangs for a second or more. This is not acceptable because you want it as close to real time as possible.

Finding the solution

I know this particular example because I ran into it last week. I implemented the ICallbackEventHandler and the related methods with the purpose of sending the filename of the image back to the JavaScript caller based on the ID of the product. This table was a server-control that didn’t allow me to add the filename as part of the data source, so I had to use AJAX.

Everything worked like a charm, but the performance was awful as described above. After trying everything from clearing the Page_Load event handler to removing all controls from the page I gave up, but I didn’t accept defeat. So, I wrote a generic handler (.ashx) which only purpose was to write the filename belonging to a product ID. Then I wrote a JavaScript function that used a HTTP request to retrieve the filename from the generic handler.

This approach was much faster than the ASP.NET built in Client-Callback feaature and as close to real time as you can get. The JavaScript function also cached the filenames to the clients’ cache, making it even faster if the same picture was to be shown more than once which I knew they would.

Choosing the right approach

I’ve used the Client-Callback feature many times in a lot of different scenarios without it giving performance issues. But in this case it did and it took me several hours of trial and error before I came up with a solution that basically wasn’t simple at all. Well, not simple compared to the Client-Callback approach and that really bothers me. I’m a keep-it-as-simple-and-clean-as-possible kind of developer and although the solution wasn’t very complex or hard to do, it’s still more complicated.

Even though I love the simplicity of the ASP.NET Client-Callback implementation, I have to admit that I’m probably not going to use it in the future. There’s a lot of great AJAX JavaScript libraries that let’s me keep the simplicity of the client-side code and at the same time harness the raw power of a generic handler. I’m sorry Microsoft, but you killed performance for the sake of simplicity on this one.

ASP.NET is a double sided discipline that demands skills and understanding of two very different worlds: the web as a platform and .NET development. The problem is that it is hard to find an ASP.NET developer that is strong in both disciplines. Let me elaborate.

By the web as a platform, I mean that the developer must have absolute understanding of how the web server request/response works. He must also be fluently in XHTML, JavaScript, CSS and AJAX to some extent. He must know how to deploy and implement a web solution on a web server. In order to manage these disciplines, the developer must have at least 2 years of professional experience in the field.

An ASP.NET developer must also know his way around the CLR, data binding, user controls, the page event model etc. There are a lot of things in the entire ASP.NET framework that is important to master in order to take full advantage of the capabilities in ASP.NET. In order to fully master all the ASP.NET features, the developer must have a deeper understanding of the CLR and general programming. That means at least 1-2 years of professional experience.

That sounds like two different profiles: a web developer and a .NET developer. But that is not how it works. An ASP.NET developer must master both disciplines to such a degree that no task is impossible and also carried out the right way the first time.

I see two kinds of ASP.NET developers all the time. The first kind started in web development by doing HTML etc. and then switched to the ASP.NET platform. The second started development in VB6, Java, C++ or similar and then made the move to ASP.NET. Both developers are very good at their particular discipline, but not that good at the other. The VB6 guy doesn’t care about standard compliance, CSS driven design etc. and the HTML guy doesn’t care about refactoring and separating logic from design etc.

It is very rare to meet an ASP.NET developer that fully masters both disciplines. At Traceworks, we soon begin looking for such a developer, and I think it’s going to be very difficult to find the right profile. You would think that a certified .NET developer (MCAD or MCSD) with exams in both ASP.NET and low level .NET programming is the right choice by default, but that is not the case. To master any of the ASP.NET disciplines you need experience – a lot of experience. I would choose experience over certification any time.

When the time comes, I will add a link to the job opening for a true ASP.NET developer here.