Friday, May 1, 2009 - Posts

AJAX - Fileupload.HasRows returns false???

I have recently jumped on the AJAX bandwagon and am frantically trying to AJAX enable all my web pages through the use of asynchronous partial-page updates.
A typical design pattern of an ASP.NET AJAX application involves it consuming web services directly from the client without requiring postbacks to the web server. Not only do postbacks slow down an application, but they also complicate the application design, implementation, and deployment.
AJAX is so addictive and such a compelling technology that once you have gotten the hang of it, it is hard to refrain from using it.

However, all said and done, there are some pitfalls that one ought to be aware of.
This blog post is certainly not intended for what AJAX can or can’t do, but if you are looking to convert your web page and make them AJAX enabled, there are a few things you have got to keep in mind just in case you are stuck.

I had a web page with input controls on a panel all of which were wired to the validator controls. In addition, I also had a FileUpload control.

Prior to AJAX enabling the web page, everything was fine and dandy, but the minute I wrapped the asp panel in an Update Panel, everything worked but the FileUpload. In that, the control (FileUpload) did not detect the file name and returned an empty string when checking for FileUpload.HasFile.

The solution to the problem was not difficult either.
In the markup, essentially all that was missing was the PostBackTrigger with the ControlID="btnSubmit".

So essentially, all that is happening now is that we are forcing a post back on the click event of the button while everything else happens asynchronously using the Update Panel. So, when the user presses the button, the page gets refreshed and filename is detected.

My next area of interest is JavaScript Object Notation (JSON). This is just another piece of functionality that is part of the AJAX Extension toolkit typically used for serializing and deserializing data. It is somewhat akin to XML/SOAP, except that JSON is a text-based data interchange format which delivers a more consistent experience due to the implementation differences of XML/SOAP by the various browsers.


Obi />