Syed Salman Raza Zaidi
Syed Salman Raza Zaidi

Reputation: 2192

File Upload Control Change Event Not firing

I have an asp.net File upload control, I am using Jquery multi file upload with it. When I select a file, it makes a div under the upload control to display list of files. I want to save the value of upload control in a hidden field, I am using jquery change event on fileupload control but its not firing. I also tried using same event with the files div, but its also not firing, and no error in Fire Bug.

<asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
<div id="ctl00_ContentPlaceHolder1_FileUpload1" class="MultiFile-list"></div>


 $(document).ready(function () {
  $("#ctl00_ContentPlaceHolder1_FileUpload1").change(function () {
                alert("File Selected");
            });
            $(".MultiFile-list").change(function () {
                alert("File Selected");
            });             
 });

I also tried with div ID, but no luck.

Upvotes: 0

Views: 2316

Answers (1)

Daniele
Daniele

Reputation: 1938

Seems that jQuery don't support multiple file upload very well, but you can try with something like this on the change event:

$("#ctl00_ContentPlaceHolder1_FileUpload1").change(function() {
    var files = $('#ctl00_ContentPlaceHolder1_FileUpload1')[0].files;
    for (var i = 0; i < files.length; i++) {
        $(".MultiFile-list").append(files[i].name);
    }
});

As you can read, I get the files list and put the names in the div you defined, just to let you try the code.

Upvotes: 2

Related Questions