FileUpload control does not work in Update Panel and workaround

All file upload controls (includes asp, telerik, componentart, component factory and others) does not working in any AJAX update panels. 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.

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.

<asp:updatepanel id=”UpdatePanel1″ runat=”server” updatemode=”conditional”><br /><triggers><br />  <asp:postbacktrigger controlid=”Button1″><br /></triggers><br /><contenttemplate><br /><ews:datepicker id=”DatePicker1″ runat=”server” usingupdatepanel=”True” onselectionchanged=”DatePicker1_SelectionChanged”><br /> <asp:label id=”Label1″ runat=”server”></asp:Label><br /> <asp:fileupload id=”FileUpload1″ runat=”server”><br /> <asp:button id=”Button1″ runat=”server” text=”Upload” onclick=”Button1_Click”></contenttemplate><br /></asp:UpdatePanel>

The key is at the Triggers. Please note this will post a full postback even it’s inside a Update Panel.

Solutions are actually available for gmail like async file upload using iframe:
http://vinayakshrestha.wordpress.com/2007/03/13/uploading-files-using-aspnet-ajax-extensions/
http://msmvps.com/blogs/luisabreu/archive/2006/12/14/uploading-files-without-a-full-postback.aspx

Advertisements
This entry was posted in Ajax and tagged . Bookmark the permalink.

One Response to FileUpload control does not work in Update Panel and workaround

  1. nishithraj says:

    hi,

    I just came across a scenario. There are two grids. I need to populate the first gridview in page load. While clicking a row I need to display another grid with the details of corresponding row(clicked row).

    Pagemethods can’t be used here since bindgrid method has non-statical values.

    I tried with ICallbackEventHandler and XMLHTTPREQUEST. But both are not populating the second grid. I thought it’s not rendering properly. Tried with rendering that particula control. But again failed…….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s