FileUpload and Ajax UpdatePanel

All file upload controls (includes asp, Telerik, component, component factory and others) does not work in any ajax update panel and upload control needs to full page postback. This means if your upload control located in an update panel, the control does not post the file. If you look at the posted file property of the control, you will see it null. So, the control always has to post full page postback.

This is limitation comes from the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. In order to upload a file, you should perform a full page postback.

If you have an automatically AJAX-enabled button or other control, which normally does postbacks, placed in UpdatePanel you could use one of the following workarounds to make the button perform postbacks again.

1 - You need to create a PostBackTrigger for the button which should initiate postback.

<asp:updatepanel runat="server" id="UpdatePanel1">
       <contenttemplate>
           <asp:FileUpload runat="server" id="Upload1" />
           <asp:button runat="server" id="ButtonSubmit" text="Postback" />
       </contenttemplate>
       <triggers>
           <asp:postbacktrigger controlid="ButtonSubmit" />
       </triggers>
   </asp:updatepanel> 
  • You can register the page and control to do full page postback. To do this, you can use the script manager. (suggested by EtienneT)
ScriptManager.GetCurrent(Page).RegisterPostBackControl(Upload1);
  • You can use the “iframe” HTML object to call upload webpage in the frame. But this as you know iframe is not an XHTML object. But this can be the smooth fix for you. (suggested by Justin Bozoiner)

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru