File upload is not working with AsyncPostBackTrigg

2019-07-26 10:45发布

问题:

I have one html file upload control to upload the profile picture and I'm using update panel and AsyncPostBackTrigger trigger. If I use PostBackTrigger then uploading of profile image works but If I use AsyncPostBackTrigger then uploading doesn't work.

Below is my code inline:

<asp:UpdatePanel ID="pnlZerkerBasicProfile" runat="server">
<input type="file" id="myFile" name="myFile" class="file_input_hidden" onchange="javascript:FileUploadSubmit();" style="cursor: pointer;" />
<Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSaveProfilePicture" />
</Triggers>
</asp:UpdatePanel>

Can anyone help?

回答1:

This is a known issue, a full postback is required for the fileupload control to work within an updatepanel i.e. you can't use a AsyncPostBackTrigger.

Edit: Just saw this is a duplicate of FileUpload Doesn't Work When Nested In UpdatePanel? C#