'ASP.Net file upload causing post back in update panel using triggers
I have file upload control to upload the profile picture using update panel. I have used AsyncPostBackTrigger with update panel but still the page is causing full postback.
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>
Can anyone help?
Solution 1:[1]
change the trigger t a postback trigger since file upload is not available in Request.Form.AllKeys when async postback occurs via update panel. See this:
http://www.codeproject.com/Articles/16945/Simple-AJAX-File-Upload
Solution 2:[2]
This should work
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server"Text="Upload" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
Solution 3:[3]
This code should work. It will not cause postback.
<asp:UpdatePanel ID="pnlZerkerBasicProfile" runat="server">
<ContentTemplate>
<input type="file" id="myFile" name="myFile" class="file_input_hidden"
onchange="javascript:FileUploadSubmit();" style="cursor: pointer;" />
<asp:Button ID="btnSaveProfilePicture" runat="server"Text="Upload"
OnClick="btnSaveProfilePicture_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSaveProfilePicture" />
</Triggers>
</asp:UpdatePanel>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Jidheesh Rajan |
| Solution 3 | marc_s |
