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
<script type="text/javascript">
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: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:
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;
}
}