Nave Tseva
Nave Tseva

Reputation: 878

Ask the user for number of file to upload -ASPX

I'm trying to build a website (I learning this whole subject now), and maybe the anwser is very simple.

I am devaloping in ASPX/C#, and I want that in form, there is a select field (<select>) with option of number of files to upload, the max files to upload is 4.

I want that after I select the number of files, there will be some up;oad fields (in the number that I already chose).

My question is how can I do that? (maybe with javascript of AJAX ? I have no idea how)

Wish for help, Thanks.

Upvotes: 0

Views: 74

Answers (2)

user1
user1

Reputation: 1065

I am not sure if this is what you are looking for, but give it a try Try this: http://jsfiddle.net/2bZwD/

`$('#select1').change(function(){
  var count = $(this).val();
  var uploadcount = 0;
   $('.upload').each(function(){
       if (count > uploadcount)
        {
            $(this).show('slow');
            uploadcount++;
        }
       else
       {
           $(this).hide('slow');
       }
   });
});`

Upvotes: 1

Devesh
Devesh

Reputation: 4550

There will be two approach

1) Javascript : Using javascript you can read the max file number and add the Upload html tag on the document . As you are using ASPX , it will not work because when the form was build and viewstate was genetated these fields were not the part. If you will use ASP.NET MVC it will work and you easily using the jquery

2) If you want to use the ASP.NET webform you have to do the AutoPostback equals to true for the dropdown list and then read the value on the Selected Index change event on the server and file upload control on the server side. It has a drawback that it will require full post back. You can use the Updatepanel to do the partial post back and get the file controls in the page.

Upvotes: 1

Related Questions