views:

998

answers:

3

I want to show a pop-up on click of a button. The pop-up should have a file upload control. I need to implement upload functionality.

The base page has nested forms. Totally three forms nested inside. If I comment the two forms then I can able to get the posted file from Request Object. But I was not suppose to comment the other two forms. With nested forms I am not getting the posted file from the Request object.

I need some protocols to implement this.

I am using C#. The pop-up was designed using jQuery.

As suggested, I am posting the sample code here.

<form id="frmMaster" name="frmMaster" method="post" action="Main.aspx" Runat="server" enctype="multipart/form-data">

<form method='Post' name='frmSub'>       
<input type="hidden" name='hdnData' value=''>       
</form> // This form is driven dynamically from XSL


<form method='Post' name='frmMainSub'>       
<input type="hidden" name='hdnSet' value=''>        
</form>


</form>


Note:

Commenting the inner forms works fine. But as it required for other functionalities not suppose to touch those forms.

I have given this code for sample purpose. The actual LOC in this page is 1200. and the second form is loaded with lots of controls dynamically. I have been asked not to touch the existing forms. Is it possible to do this functionality with nested forms?

+2  A: 

You can have multiple HTML form tags in a page, but they cannot be nested within one another. You will need to remove the nesting for this to work. If you post some of your code, you're likely to get more help with some specific recommendations to address this.

From your posted code, it's also unclear why you'd even be tempted to use multiple forms. Can you elaborate on why you think you need multiple forms here? You don't have explicit actions in your subforms, so it's hard to tell where you want them to post, but I'm guessing it's all posting to the same page. So, why multiple forms at all?

Chris Farmer
<form id="frmMaster" name="frmMaster" method="post" action="Main.aspx" Runat="server" enctype="multipart/form-data"><form method='Post' name='frmSub'> <input type="hidden" name='hdnData' value=''> </form> // This form is driven dynamically from XSL<form method='Post' name='frmMainSub'> <input type="hidden" name='hdnSet' value=''> </form></form>
if you could post this code in your actual question it would be more helpful....
Jason
...i see you posted this in your question, actually... try doing it again but indenting all your lines 4 times, as the page is actually using your <form> tags..
Jason
asp.net pages require a <form> tag with a runat="server" attribute to run, and pretty much all other content has to reside within that form tag for the page to work as expected if you want to take advantage of all the abstractions of asp.net.
Doug R
A: 

In your situation you're looking at a hack no matter how you put it. You aren't supposed to have nested forms.

Since you're using Javascript to do this, you could try moving the form element that is posting back out of the parent forms and then performing the .submit() action after it's been moved.

It's a ugly hack - but I so is the HTML -- :) (I kid, I kid!)

Hugoware
Its an existing page I cant do much for that. :)
I'm not saying you move the actual HTML - I'm suggesting you rebuild it on the fly using Javascript, but build it outside the parent form and then submit it from there
Hugoware
+1  A: 

You could always try putting one of the inner forms onto another page and serving it up in an iframe. That way the inner form is not technically inside the outer form. This will require you to alter some of the html, but there's really no way around that.

Doug R
Thanks for the suggestion.