AsyncFileUpload postback causes double upload

前端 未结 6 1734
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 02:32

I implemented the AsyncFileUpload control on a web page. This web page requires uploaded files to appear in a GridView.
The GridView

6条回答
  •  死守一世寂寞
    2020-12-07 03:18

    Maybe ugly, but works:


    1) Add a css-hidden asp:Button bellow the asp:AsyncFileUpload AsyncFileUpload1 control.

    2) On the Page_Load method, remove the if (Request.Params.Get("__EVENTTARGET") == "UploadPostback") and put its block in a simple else to the previous if.

    3) On the AsyncFileUpload1_UploadedComplete function, also remove the if (Request.Params.Get("__EVENTTARGET") != "UploadPostback") line, but leave intact everything that was inside it.

    4) Back to the aspx. Put a asp:UpdatePanel outside the grid GridView1.

    
         
             
         
         
    
         
    
        
    
    

    5) The last step is to change the AjaxUploadComplete client-side javascript function to make it trigger the postback. Replace it with the following:

    function AjaxUploadComplete() {
        var btnClick = document.getElementById("btnClick");
        btnClick.click();
    }
    

    Any file the user selects is uploaded only once.
    All changes here are meant to be made in AjaxUpload.aspx & AjaxUpload.aspx.cs of your AjaxUpload.zip.

提交回复
热议问题