Ajax Upload Control HTML:
<ajaxctrl:asyncfileupload id="AsyncFileUpload1" runat="server" uploaderstyle="Traditional" xmlns:ajaxctrl="#unknown">
OnClientUploadError="uploadErrorHandler" OnUploadedComplete="ProcessUpload" OnClientUploadStarted="uploadStarted"
Width="110px" ClientIDMode="Static" Style="position: absolute; z-index: 2; opacity: 0;
filter: alpha(opacity=0); border: solid 1px red;" ToolTip="Upload Photo" ThrobberID="UpdateProgress1" /></ajaxctrl:asyncfileupload>
Handle EventFunctions:
function uploadErrorHandler(sender, args) {
}
function uploadStarted(sender, args) {
if (validateFileExtension(args.get_fileName())) {
var fileSize = args.get_length();
if (parseInt(fileSize) > 3800000) {
alert('File exceeds the file size limit.Maximum size is 19MB');
args.set_cancel(true);
return false;
}
}
else {
alert("Invalid file '" + args.get_fileName() + "'.Supported file types are '.jpg, .jpeg, .gif, .png, .bmp' ");
args.set_cancel(true);
return false;
}
}
C# Code:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
Boolean isValidFile = Utility.isValidFile(e.FileName, new String[] { ".gif", ".jpg", ".bmp", ".png" });
if (isValidFile)
{
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img", "alert('Invalid Image File!');", true);
}
}