FileUpload Control not working in UpdatePanel

You may have experienced the problem with FileUpload control in an UpdatePanel – when you hit the submit button, Request.Files.Count always returns 0, even though you had registered the submit button as a PostBackControl and a PostBackTrigger of the UpdatePanel containing the FileUpload control.

In my case, the FileUpload only works when it is visible when the page is first time loaded (not a postback).  It will not work (Request.Files.Count returns 0) when it is hidden originally and then made visible during later AsyncPostBacks.  Maybe ASP.NET is confused, because I am also changing the submit button’s postback type between full postback and aysnc postback.  The submit button is used by other things, and I only want it to fire a full post back when files need to be uploaded, and in all other cases, I want it to fire async postback and only do partial update on my page.

I spent many hours trying many different solutions I saw on the internet, but none of them worked for me.  However, I found an important hint which led me to the final working solution.  That is the Enctype attribute of the Form.  I learned that the Form.Enctype has to be “multipart/form-data” when files need to be uploaded.  I think this is set automatically for you in normal cases, but it isn’t set up correctly in my case.  So, I manually set it to “multipart/form-data” in OnInit of my user control, and it solves the problem.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Twitter

Filed under: Application Development | Posted on January 25th, 2010 by Geer

Tags: , , ,

One Response to “FileUpload Control not working in UpdatePanel”

  1. Masthanvali Shaik Says:

    This solved my image upload problem which i am trying to solve from many hours. Thanks a lot

Leave a Reply

Links

Topics

Tags

Authors

Syndication

Archives

Copyright © 2012 Pearl Technology. All rights reserved.
The Tech Blue theme was modified to help create this blog.