Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
once i select the file using asyncfileupload, the file is already uploading to the server. once finished, i click the button, then the file originally uploaded upload again to the server.

i tried whatever i could, please advice :(

javascript
JavaScript
<script type="text/javascript">
        //upload file
        function uploadError(sender, args) {
            document.getElementById('lblStatusFupFile').innerText = args.get_fileName(), "" + args.get_errorMessage() + "";
        }

        function StartUpload(sender, args) {
            document.getElementById('lblStatusFupFile').innerText = 'Uploading...';
        }

        function UploadComplete(sender, args) {
            var filename = args.get_fileName();
            var contentType = args.get_contentType();
            var text = "File name: " + filename + " is uploaded.";
            document.getElementById('lblStatusFupFile').innerText = text;
        }       

</script>
HTML
ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <Triggers>
               <asp:PostBackTrigger ControlID="btnUpload" />
           </Triggers>
       <ContentTemplate>
       <p>
           <asp:Button runat="server" Text="Upload" ValidationGroup="upload" ID="btnUpload" OnClick="btnUpload_Click"></asp:Button>
       </p>
       <p>
           <asp:AsyncFileUpload runat="server" OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" OnClientUploadError="uploadError" ThrobberID="ThrobberFile" UploadingBackColor="#66CCFF" Width="400px" FailedValidation="False" UploaderStyle="Modern" ID="fupFile" OnUploadedComplete="fupFile_UploadedComplete"></asp:AsyncFileUpload>
           <asp:Label ID="lblStatusFupFile" runat="server" Style="font-family: Arial; font-size: small; color: #000000;"></asp:Label>
           <asp:Label runat="server" ID="lblValAfuFile" Style="color: #FF0000; font-weight: 700"></asp:Label>
       </p>
           </ContentTemplate>
           </asp:UpdatePanel>


code behind:
C#
 protected void fupFile_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
       {
               if (fupFile.HasFile)
               {
                   string strPath = MapPath("~/Uploads/files/") + Path.GetFileName(e.FileName);
                   fupFile.SaveAs(strPath);
               }
       }

protected void btnUpload_Click(object sender, EventArgs e)
       {
           if (this.fupFile.FileName == "")
           {
               this.lblValAfuFile.Text = "* File required.";
               return;
           }
     //some code
       }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900