Hi.
The behavior of "
AjaxFileUpload" is different from "
AsyncFileUpload" which also has its own bugs: for some developers these errors are triggered and not for others. And the source code of AjaxControlToolbox, not help because the files and start down with mistakes to go adjusting. In my case, when I required to develop professional applications, you can not expect the stability of the AjaxControlToolkit. We understand that developers of AjaxControlToolkit have made a great effort, but I think it is not enough to trust and include it in production applications.
With asp:AjaxFileUpload the OnClientUploadError not fired. I have similar bug.
Test this example:
The code validate the size of file onClient. When Size > 1000000 fire exception. The exception not fired OnClientUploadError="uploadError" and the file was upload to the server.
I need to validate de size of file onCliente to prevent the fileupload on the server (including temporary file uploaded to the server)
<script type="text/javascript">
function uploadError(sender, args) {
var ArchivoNombre = args.get_fileName();
var MensajeError = args.get_errorMessage();
var Mensaje = "Archivo no cargado: " + ArchivoNombre + " / ERROR..." + MensajeError;
}
}
function uploadComplete(sender, e) {
var Peso = context.get_fileSize();
var ArchivoNombre = context.get_fileName();
if (parseInt(Peso) > 1000000) {
var Mensaje = "Archivo excede el tamaño límite de 2 Mb. Archivo : " + ArchivoNombre + " Peso(bytes): " + Peso;
var displayElement = document.getElementById("ResultId");
displayElement.innerHTML = Mensaje;
var err = new Error();
err.name = 'Error Uploading';
err.message = 'Excedió el límite.';
throw (err);
}
else {
}
}
</script>
Some HTML:
<body>
<form id="form1" runat="server">
<div>
<asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
</asp:toolkitscriptmanager>
<asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
OnClientUploadComplete="uploadComplete"
OnClientUploadError="uploadError"
onuploadcomplete="AjaxFileUpload1_UploadComplete" />
<div id="testuploaded" style="display: none; padding: 4px; border: gray 1px solid;">
<h4>
list of uploaded files:</h4>
<hr />
<div id="fileList">
</div>
</div>
<p>
<span style="background-color:Aqua" id="ResultId"></span>
</p>
<asp:button id="btnSubmit" runat="server" text="Postback" />
</asp:ajaxfileupload></div>
</form>
</body>
CodeBehind:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs file)
{
string rutaUploads = HttpContext.Current.Server.MapPath("Uploads\\");
string FullNombre = rutaUploads + file.FileName;
AjaxFileUpload1.SaveAs(FullNombre);
}