Thursday, June 26, 2008

AJAX - ASP.NET File Upload Problem

In ASP.NET 1.1, if you wanted to upload a file you needed to make sure that you added the following text to your ASP.NET form declaration:

In ASP.NET 2.0 adding a file upload control to the form must have done this behind the scene since this was no longer a requirement.

I've been fighting an issue in my application where the file didn't get uploaded the first time the form was rendered, I have an update panel with a grid that when clicked upon displays the details record.  That detail record then has file upload control, and uses the method I wrote about earlier to upload the file within a control rendered in an Update Panel.

Although I haven't spent the extra time tracking this down to the bits, it's my assumption that the page originally get's rendered without the FileUpload control and the Form doesn't contain the encoding type.  Then when the file upload control does get rendered to the page, it doesn't update the form encoding type attribute.  So the solution is to just add the enctype='multipart/form-data' to the form tag.  This seems to resolve the issue and does indeed make sense.


No comments:

Post a Comment