tags:

views:

201

answers:

5

I have a form in asp.net with a FileUpload control inside. Next to this control I have "Upload" button which is used to upload a file to a list of files. The problem is that I also have "Submi"t button used for submiting whole form.

Now when somebody selects a file through browse button and presses on "Submit" not "Upload" file is being uploaded and I wouldn't want that.

I'm hoping for asp.net or general HTML answer

+1  A: 

Sounds like the FileUpload control and Upload button should be inside it's own form. With ASP.NET and the 1 server-side form restriction, you may have to resort to regular HTML controls to do this.

Alternatively, you may be able to use JavaScript to clear the FileUpload if Upload isn't clicked. Browsers can be picky about access to file inputs, though (for security reasons) so it may not be accessible.

Mark Brackett
+1  A: 

For the general HTML answer, have your file upload button be part of a separate form from the other form, meaning they are encapsulated within separate Form tags.

For ASP.NET, you're going to have more pain, since ASP.NET by default has only one form per page.

Ultimately, however, I think you're better off rethinking your design. Try to put that file upload on a separate page; if you have a page that does more than one thing, you're inviting confusion on the part of the user.

Randolpho
A: 

Submit button will send all of the form's information.

Try putting the FileUpload control outside, on a diferent form.

Gerardo
A: 

Your FileUpload control needs to be in its own form if you want to to be submitted separately. When you click the Upload button, the other parts of your form are being submitted as well. That's just how it works.

Josh Stodola
A: 

I would separate the two forms. Using JavaScript or something like that could get to be a pain. The problem with separating the forms is you have to do it in a way where you don't lose your original form, meaning if you have other form information around the file upload you might have a bit of a nightmare on your hands but if you can put the file upload either above or below the form that submit controls then it's easy.

<form id="A">
  <button name="submit>
</form>
<form id="B">
  <fileupload>
</form>

I use this method on one of my sites and it works quite well.

Robert