Monday, July 25, 2011

Troubleshooting Ajax AsyncFileUpload Control

The ASP.Net Ajax Control Toolkit provides lots of interactive, feature-rich controls for the web developer. However, as my work transitioned from Visual Studio 2008 to Visual Studio 2010 products, I noticed a common problem with the Asynchronous File Upload control. The error message from trying to use the control was "The file attached is invalid".

 

If you're not familiar with this control, it behaves similarly to the normal File Upload control that's in the Standard section of the Tools panel in Visual Studio. Both versions of the control allow a user of the web application to browse for, select, and upload a file to the server. However, the Ajax toolkit's Asynchronous version allows the upload process to occur in real time (in the background) as the user continues to use the webpage, instead of forcing the user to wait for the page to be returned while the upload is being processed.

 

The issue appears to be with the control itself, but particularly when used in the .Net 4.0 framework, which is likely to be the default for Visual Studio 2010 products, unlike the 3.5 framework likely set as the default for Visual Studio 2008.

 

So, how do you fix the AsyncFileUpload that keeps telling you "The file attached is invalid"?

The Fix

Just add the ClientIDMode="AutoID" property to the control. This easy change allows the control to be properly identified. If you would like to control this at the web.config level, you could also consider using the following approach instead:



<pagecontrolRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>


Of course, in that case you will want to be sure to test the rest of your controls to make sure this doesn't cause any problems elsewhere.

For additional reading on the topic, see:


- Eric Reid, Design Expert; CTT+, ACI (Adobe Certified Instructor), ACE (Adobe Certified Expert), i-Net+, IC3
LinkIn with Eric


Bookmark and Share

No comments:

Post a Comment