FileUpload Doesn't Work When Nested In UpdatePanel? C# FileUpload Doesn't Work When Nested In UpdatePanel? C# ajax ajax

FileUpload Doesn't Work When Nested In UpdatePanel? C#


Basically you just need to make your button do a full postback to send the file. Also make sure that you have this.Form.Enctype = "multipart/form-data"; set in your code, or you can put in that page. AsyncPostbacks don't work with files for security reasons as mentioned, without hacks. (I've never been able to get it to work).

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">      <ContentTemplate>           <asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />      </ContentTemplate>      <Triggers>         <asp:PostBackTrigger ControlID="Button1" />      </Triggers> </asp:UpdatePanel>


For security purposes, browsers don't let you post files via javascript. Imagine if I could write a little bit a javascript to asynchronously submit the contents of your My Documents folder to my server.

So javascript-ish methods of posting the form, like the XMLHttpRequest used by the UpdatePanel, won't work.

This post describes a decent work around if you're on 3.5 SP1. http://geekswithblogs.net/ranganh/archive/2009/10/01/fileupload-in-updatepanel-asp.net-like-gmail.aspx

And this post describes a couple work arounds if you'd prefer not to use the AjaxControlToolkit. http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx


File Upload will not work with a partial post back.So just add this line at your page load

ScriptManager.GetCurrent(this).RegisterPostBackControl(this.YourControlID);

Or use PostBackTrigger.

<Triggers>            <asp:PostBackTrigger ControlID="YourControlID" /></Triggers>

Or You need special AsyncFileUpload control as defined in AjaxControl Toolkit.

<ajaxToolkit:AsyncFileUpload OnClientUploadError="uploadError"     OnClientUploadComplete="uploadComplete" runat="server"     ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern"     UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" />

You can check here.