Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET FileUpload in UpdatePanel - still not working

Attempting to use a FileUpload or AsyncFileUpload control in an updatepanel on a NET 4.5/C# web application.

I've tried using either standard Scriptmanager or ToolKitScriptManager in my masterpage.

My Save button is set as a PostBackTrigger (tried AsyncPostbackTrigger too).

No matter what, my (Async)FileUpload.HasFile always returns false.

Remove the updatepanel and both uploadcontrols work fine.

What really throws me is that I have this working in another project (scriptmanager in masterpage, Fileupload in updatepanel, SaveButton is PostbackTrigger).

Is there some specific AJAX version or .NET version that can cause problems?

This is extremely frustrating.

like image 682
user981235 Avatar asked Oct 15 '14 18:10

user981235


2 Answers

Adding the button to the UpdatePanel's trigger tag, I got it working:

<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        <asp:FileUpload ID="FileUpload" runat="server" />
        <asp:Button ID="btnUpload" runat="server" Text="Upload"
           OnClick = "btnUpLoad_OnClick" />               
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID = "btnUpload" />
    </Triggers>
</asp:UpdatePanel>

I did not have to do anything different server-side (like user5159158's answer).

like image 186
callisto Avatar answered Sep 22 '22 03:09

callisto


In Page_Load add: Page.Form.Attributes.Add("enctype", "multipart/form-data");

like image 33
Tran Anh Hien Avatar answered Sep 25 '22 03:09

Tran Anh Hien