Friday, January 11, 2013

Handler (ashx) VS Page (aspx)

We used to do development with Page (aspx) which comes with lots of rapid application development feature such as postback handling, drag & drop support, etc. But, this becomes expensive when the application is hosted in the Internet (not in a LAN). The viewstate, the control object instance generation, etc are all come with a price. A more complicated situation is that when you try to use AJAX (ScriptManager + UpdatePanel), the performance become questionable (when traffic goes up) and the coding become very complicated.

On the other hand, Handler (ashx) is a class that provides very basic functionality as compared to Page. There is no visual designer for Handler. No viewstate. No control object generation. No postback. You have to handle everything by yourself. The advantage of Handler as compared to Page is the performance (by giving up all the rapid application development features).

With JQuery and JSON, implementing AJAX become very easy. Modifying the DOM objects at the client site become easier as well. Using JQuery AJAX call to the Handler will boost up the performance because the viewstate is no longer require to transmit back and fore between the server and the client. At the server side, it also does not requires to re-generate all the control object instances.

Try this out:
  • Design a data entry form in Page (aspx).
  • Click on the Submit button and the client will make a AJAX call to the Handler (ashx) with the user input values.
  • Then, the Handler will return the result in JSON format to the client.
  • The client will then check the result and make the appropriate response.
 Benefits of using Handler (ashx) + Page (aspx):
  • Faster response time
  • Reduce the data to be transmitted between the server and the client.
  • The server CPU load will reduce due to the Page call is lesser.
 Challenges:
  • The developer requires to more JavaScript/JQuery knowledge.
  • Harder to debug.
  • Because the input controls in the Page is sometimes unpredictable (in .Net 3.5), getting the input field with JQuery will become troublesome.


No comments:

Post a Comment