How can I call this Javascript function from the code-behind without refreshing the page?
function fileUploaded(fileName) {
// Send FileName off to AJAX call to do something with it
}
... I'm using the FileUpload .Net component in the .aspx to upload multiple files all at once:
<form runat="server">
<asp:FileUpload runat="sever" id="FileUpload1" AllowMultiple="true"/>
<asp:Button runat="server" OnClick="UploadMultipleFiles"/>
</form>
... In the code-behind I'm looping through each of the posted files and saving them on the server one at a time. After each file is saved, I'm trying to call the Javascript function, fileUploaded, on the client side:
protected void UploadMultipleFiles(object sender, EventArgs e) {
FileUpload FileUpload2 = (FileUpload)this.FindControl(FileUpload1);
if (FileUpload2.HasFiles)
{
foreach (HttpPostedFile postedFile in FileUpload2.PostedFiles)
{
fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(lblPath + fileName);
// Used ScriptManager.RegisterStartupScript too
ClientScript.RegisterStartupScript(this.GetType(),
"fileUploaded" + _intScriptIndex++,
"fileUploaded('" + fileName + "');", true);
}
}
... The "Problem" is that the code behind doesn't call the Javascript function until all files have been uploaded. It reloads the page with the following appended to the end of the DOM:
<script type="text/javascript">
//<![CDATA[
fileUploaded('00007.MTS');fileUploaded('00009.MTS');fileUploaded('00012.MTS');//]]>
</script>
The "Question" is, How do I call the Javascript function fileUploaded from the code-behind immediately after each file is saved without reloading the page?