Hi nauna,
You have to use OnClientUploadComplete event to define a javascript function to call the Code Behind function.
For calling code behind method refer below article.
Call Code Behind function from Client Side (JavaScript) in ASP.Net
Refer the below example.
HTML
<asp:ToolkitScriptManager runat="server" EnablePageMethods="true">
</asp:ToolkitScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUpload11" runat="server" MaximumNumberOfFiles="5"
Width="400px" OnUploadComplete="OnUploadComplete" OnClientUploadComplete="uploadComplete" />
<br />
<asp:Label ID="lblMesg" runat="server" />
<script type="text/javascript">
function uploadComplete(sender) {
PageMethods.GetCurrentTime(OnSuccess);
}
function OnSuccess(response, userContext, methodName) {
$get("<%=lblMesg.ClientID%>").innerHTML = response;
}
</script>
C#
protected void OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
string fileName = Path.GetFileName(e.FileName);
string filePath = "~/Uploads/" + fileName;
AjaxFileUpload11.SaveAs(Server.MapPath("~/Uploads/" + fileName));
}
[System.Web.Services.WebMethod]
public static string GetCurrentTime()
{
return "The Current Time is: " + DateTime.Now.ToString();
}
Screenshot