You can use the OnClientUploadStart property in the control to run the JavaScript function to check, for example:
<cc1:AsyncFileUpload ID="FileUpload" runat="server" OnClientUploadStarted="checkExtension" />
Then enter the script on your page or include:
function checkExtension(sender, args) { var ext = args.get_fileName().substring(filename.lastIndexOf(".") + 1); if (ext != 'png') { args.set_cancel(true); //cancel upload args.set_errorMessage("File type must be .png"); //set error message return false; } return true; }
In this case, we simply use the various bits of the client-side API to get / check the extension, return false and stop downloading / setting the error message (optional) if it is not valid.
Nick craver
source share