Validate AsyncFileUpload using java-script. [Resolved]

Posted by Allemahesh under ASP.NET AJAX on 3/14/2014 | Points: 10 | Views : 9718 | Status : [Member] [MVP] | Replies : 1
I am using AsyncFileUpload in my web application to upload the pdf file asynchronously. Now I want to validate the file type and size using java script.
Can any one help me.


Posted by: Allemahesh on: 3/14/2014 [Member] [MVP] Silver | Points: 25


I finally got the solution:-

There is no way to get the current file size before uploading the file. But we can get the file type by using the code:-

I have called the below java-script function:-

function UploadStartedPdf(sender, args) {
var filename = args.get_fileName();
var fileSize = args.get_length();
var ext = filename.substring(filename.lastIndexOf(".") + 1);
if (ext != 'pdf') {
throw {
name: "Invalid File Type",
level: "Error",
message: "Invalid File Type (Only .png)",
htmlMessage: "Invalid File Type (Only .png)"
return false;
return true;

<ajaxtoolkit:AsyncFileUpload ID="AsyncFileUpload" Width="200" runat="server" OnClientUploadError="uploadError" ClientIDMode="AutoID" OnClientUploadStarted="UploadStartedPdf" OnClientUploadComplete="uploadCompletePdf" CompleteBackColor="White" UploaderStyle="Modern" ErrorBackColor="Red" ThrobberID="Throbber" OnUploadedComplete="AsyncFileUpload_UploadedComplete" />

Happy Coding.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response