Maybe ugly, but it works:
1) Add a css-hidden asp: button at the bottom of asp: AsyncFileUpload AsyncFileUpload1 .
<asp:Button runat="server" ID="btnClick" Text="Update grid" style="display:none"/>
2) In the Page_Load method, remove if (Request.Params.Get("__EVENTTARGET") == "UploadPostback") and put its block in a simple else in the previous if .
3) In the AsyncFileUpload1_UploadedComplete function AsyncFileUpload1_UploadedComplete also delete the line if (Request.Params.Get("__EVENTTARGET") != "UploadPostback") , but leave everything inside it intact.
4) Back to aspx. Place asp: UpdatePanel outside the grid of GridView1.
<asp:UpdatePanel runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnClick" EventName="Click" /> </Triggers> <ContentTemplate> <asp:GridView ID="GridView1" ... YOUR GRID CODE REMAINS THE SAME </asp:GridView> </ContentTemplate> </asp:UpdatePanel>
5) The final step is to change the javascript function on the client side of AjaxUploadComplete to call the postback function. Replace it with the following:
function AjaxUploadComplete() { var btnClick = document.getElementById("btnClick"); btnClick.click(); }
Any file that the user selects is downloaded only once.
All changes here must be made in AjaxUpload.aspx and AjaxUpload.aspx.cs of your AjaxUpload.zip.
source share