views:

218

answers:

3

I have an ASP.NET file upload control which sits as part of a form. The file upload control is on the content page while the form definition is on a master page across the site. I've added multipart/form-enc to the form on the master page.

I'm using jQuery to submit the form as I show a dialog box from jQuery UI.

When I post, no file is returned to the server. The file upload control has no file and HttpFileCollection is empty. How can I find the posted file?

A: 

Try using the JQuery Forms Plugin? http://plugins.jquery.com/project/form/

See this example: http://malsup.com/jquery/form/#file-upload

Here is another example: http://malsup.com/jquery/form/file/

Daniel Dyson
I'm not using XMLHttpRequest to pass the file. I'm simply using jQuery to submit the form which then posts back to the ASP.NET page.The example uses iframes which isn't ideal.
tooba
A: 

I think it could be a problem with persistence. Check this out:

http://forums.asp.net/p/1173651/1971535.aspx#1971535

HTH

Raja
+1  A: 

Most dialogs take your content, wrap it, and place the result just before </body> in the page...this is a problem in ASP.Net because that's outside the <form></form>, it needs to be inside to be included in the POSTed data.

When you create the dialog, make it append inside the <form> when it finishes instead of the <body>, for example this is what you'd do with the jQuery UI dialog:

$("#myDiv").dialog({ ...options... }).parent().appendTo("form:first");

Now that it's been moved inside the <form>, it should post correctly.

Nick Craver
I think it's something along these lines as all the form values are blank. I've added the append code but still the same problem.
tooba
Is there only one <form> tag on your page? If so, that .appendTo() code should work-- otherwise you need to specify the actual form ID, like .appendTo('#formidhere');
Nicholas H
@Nicholas - The OP is using webforms...only one `<form>` tag, one of the defining characteristics :)
Nick Craver
You can use more than one form tag on a page with ASP.Net...
Nicholas H
@Nicholas - Not with ASP.Net **WebForms** (he's using the File Upload Control), not unless you're really hacking around.
Nick Craver
Nick, jQuery doesn't care if it's a server-side <form> tag or just a regular form tag. You can have multiple form tags on your page, as long as only one is runat="server". I've done it with PayPal integration, among other things.
Nicholas H
@Nicholas - Read the question "the form on the master page", you can't have nested forms (it's invalid), he has a single form, this is by far the most common scenario in WebForms. I never said you couldn't have multiple forms, but seeing as he's using a **control**, it *must* have the `runat="server"`, and of those you can only have one.
Nick Craver