If your talking about ASP.NET, you would first add a ScriptManager from the Toolbox (under AJAX Extensions).
Then add an AsyncFileUpload control (from AjaxToolKit).
This control has an OnClientUploadComplete event in properties. Tie it to a function, for example uploadComplete.
Your ASPX code should look something like:
<head runat="server">
<title></title>
<script type = "text/javascript">
function uploadComplete(sender) {
$get("<%=Label1.ClientID%>").style.color = "blue";
$get("<%=Label1.ClientID%>").innerHTML = "Successfully Uploaded";
}
function uploadError(sender) {
$get("<%=Label1.ClientID%>").style.color = "red";
$get("<%=Label1.ClientID%>").innerHTML = "Upload failed.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label2" runat="server" Text="Asynchronous File Uploading"
ForeColor="#000066"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:AsyncFileUpload OnClientUploadError="uploadError"
OnClientUploadComplete="uploadComplete" runat="server"
ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern"
CompleteBackColor = "White"
UploadingBackColor="#CCDDEE" ThrobberID="inProgress"
OnUploadedComplete = "FileUploadComplete"
/>
<asp:Image ID="inProgress" runat="server" ImageUrl = "~/inProgress.gif" />
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>
</body>
Your codebehind file (.cs) should look something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AjaxUploadFile : System.Web.UI.Page
{
protected void FileUploadComplete(object sender, EventArgs e)
{
string savePath = @"F:\BLOG\Projects\InsertData\UploadedFiles\";
string filename = AsyncFileUpload1.FileName;
if (AsyncFileUpload1.HasFile)
{
savePath += filename;
AsyncFileUpload1.SaveAs(savePath);
}
}
}
This should give you the async file uploading functionality you want. You can get the AjaxToolKit from http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/