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.
Tags: AJAX, ASP.NET, FileUpload, UpdatePanel
October 9th, 2010 at 11:14 am
This solved my image upload problem which i am trying to solve from many hours. Thanks a lot