FileUpload and Ajax UpdatePanel

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

This is a 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 automatically AJAX-enabled button or other control, which normally does postbacks, placed in UpdatePanel you could use one of following workarounds to make the button to perform postbacks again.

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

<asp:updatepanel runat="server" id="UpdatePanel1">
           <asp:FileUpload runat="server" id="Upload1" />
           <asp:button runat="server" id="ButtonSubmit" text="Postback" />
           <asp:postbacktrigger controlid="ButtonSubmit" />

2 - You can register the page and control to do full page postback. To do this, you can use the script manager. (suggested by EtienneT)


3 - You can use the "iframe" html object to call upload webpage in frame. But this as you know iframe is not a XHTML object. But this can be smooth fix for you. (suggested by Justin Bozoiner)

No comments:

Post a Comment