locked
Why doesn't Async File upload hit UploadCompleted event ? RRS feed

  • Question

  • User-886220824 posted

    I have used Ajax Async File Upload in UpdatePanel, It shows that file has been uploaded but it doesn't hit Uploaded Complete Event.

     protected void FileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            HdnFieldHasFileUploaded.Value = "1";
        }

    why ?

    Wednesday, January 13, 2016 12:26 PM

Answers

  • User61956409 posted

    Hi StackUnderflow,

    The following sample works fine on my side, AsyncFileUpload UploadedComplete event could fire. You could refer to it.

    <script>
        function uploadComplete(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File Uploaded Successfully";
        }
        function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File upload failed.";
        }
    
    </script>
    
    <div>
        <asp:AsyncFileUpload OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete"
            runat="server" ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern" CompleteBackColor="White"
            UploadingBackColor="#CCFFFF" ThrobberID="imgLoader" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
        <asp:Label ID="lblMesg" runat="server" Text=""></asp:Label>
    </div>
    
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
    
        string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
    
        AsyncFileUpload1.SaveAs(Server.MapPath("FileUploads/") + filename);    
    
    }
    

    Best Regards,

    Fei Han




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 14, 2016 2:42 AM

All replies

  • User-886220824 posted

    ???

    Wednesday, January 13, 2016 5:07 PM
  • User61956409 posted

    Hi StackUnderflow,

    The following sample works fine on my side, AsyncFileUpload UploadedComplete event could fire. You could refer to it.

    <script>
        function uploadComplete(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File Uploaded Successfully";
        }
        function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File upload failed.";
        }
    
    </script>
    
    <div>
        <asp:AsyncFileUpload OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete"
            runat="server" ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern" CompleteBackColor="White"
            UploadingBackColor="#CCFFFF" ThrobberID="imgLoader" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
        <asp:Label ID="lblMesg" runat="server" Text=""></asp:Label>
    </div>
    
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
    
        string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
    
        AsyncFileUpload1.SaveAs(Server.MapPath("FileUploads/") + filename);    
    
    }
    

    Best Regards,

    Fei Han




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 14, 2016 2:42 AM