Sultan
Sultan

Reputation: 69

How to count total selected files on AjaxFileUpload on change java script

Greetings!!

I am trying to count total numbers of files have been selected or dropped in file dropbox in AjaxFileUpload controller. It shows on number of files in Queue. I need to access the numbers of files in queue. How could I do that. I am trying to write onchange event for AjaxFileUpload but it's not working which works for ASP File Uploder.

It will be helpful if I get the number of files have been selected on AjaxFileUpload change.

Thanks

Upvotes: 7

Views: 1391

Answers (3)

csharpbd
csharpbd

Reputation: 4066

You can count number of file uploaded successfully from JavaScript by using OnClientUploadComplete event. Please check below:

AjaxFileUpload Code:

<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" OnClientUploadComplete="uploadcomplete" OnUploadComplete="AjaxFileUpload1_UploadComplete" Mode="Auto" runat="server" /> 

JavaScript Ccode:

<script type="text/javascript"> 
    var totalUploaded = 0; 
    function uploadcomplete()  
    {  
        totalUploaded += 1;
    }  
</script> 

For more details about this, please check AJAX Control Toolkit Tutorial: AjaxFileUpload.

Upvotes: 3

Zulqarnain Jalil
Zulqarnain Jalil

Reputation: 1691

you can use "UploadComplete" event to do this

   protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
                {
                   HttpFileCollection uploads = HttpContext.Current.Request.Files;
                    int NoOfFiles = uploads.Count
    }

Upvotes: 1

Gi1ber7
Gi1ber7

Reputation: 682

As for my understanding: AjaxFileUpload.js library doesn't support multiple uploads by itself. So you have to implement the multi-file upload by yourself. There are others libraries that support multiple files upload out of the box: Fine Uploader 5 seen to be a nice one.

If you need to use AjaxFileUpload you can follow this stackoverflow question that is related of what you want to do upload multiple files with ajaxFileUpload with different file ids . Then you can add a counter for as many times as you call the function.

Upvotes: 1

Related Questions