I am using the new AsyncFileUpload control from the latest AjaxControl ToolKit. My query is regarding the OnClientUploadStarted event which is fired before the upload is started. Is there any way to cancel the upload, as I am checking the fileExtension at this point and would like to cancel the upload so that it does not continue and go on to upload the file. My end result is allow only images to be uploaded. Please advise and thanks for your time.
+1
A:
You might try adding a "Regular Expression Validator" to the field, and see if you can use that to validate the file selected before the upload starts.
Mitchel Sellers
2009-10-13 13:30:24
I tried adding a custom validator, however the validation event is not fired until the form is submitted, however the file is uploaded instantaneously once selected. Hence, my option is to use the OnClientUploadStarted event
Sloane
2009-10-13 13:58:20
You mean a Regex validator can't suffice? It has built-in client-side validation. If you build your own custom validator, you can attach a client-side function as well.
o.k.w
2009-10-13 14:57:25
+1
A:
Got the answer, all I had to do was override the javascript function with this script(not the best answer, but works), you all could have done faster and cleaner
var orig = AjaxControlToolkit.AsyncFileUpload.prototype.raiseUploadStarted;
AjaxControlToolkit.AsyncFileUpload.prototype.raiseUploadStarted = function(e) {
var evt = this.get_events()._getEvent('uploadStarted');
if (evt) {
if (evt.length > 1)
return orig(e);
else if (evt.length === 1)
return evt[0](this, e);
}
}
Sloane
2009-10-14 18:00:11
A:
Hi, I have exactly same issue... can you be more descriptive.
What this overriding is doing here.
AmiT
2009-11-30 10:05:34
The Ajax Control Toolkit has had an update for the AsyncFileUpload control. I have not checked the new one out but I hope this issue is fixed in the newer version.As explained before, the return values from the function you attach to OnClientUploadStarted event are not used at all. You can check by debugging the javascript, this particular function originally just calls the function and not use the return value(true/false use false to stop the upload). This override ensures the return values are used by the internal event.
Sloane
2009-12-03 09:18:56
Here is the link for all the updateshttp://ajaxcontroltoolkit.codeplex.com/SourceControl/ListDownloadableCommits.aspx
Sloane
2009-12-03 09:20:05
A:
kindly tell me where to put this code as i want to cancel the Upoload if file is not a image file within desired Size
Ankur
2010-07-08 05:28:22