Nested Forms in ASP.NET

N

~~~ .NET Ed ~~~

Hi,
As you all know when an ASP.NET web form is created that will include
web controls and such, it contains a
FORM that that identifies the web form and its containing controls.

Well, I have a web form who has several other (user & custom) controls,
these are enclosed within the standard
FORM tag. Additionally *some* of these user controls are actually forms as
well. This results into nested Forms.

I was noticing that this seems to cause certain confusion on the browser
sometimes. I checked the HTML and it is ok.

It has the following forms:
1. ASP.NET Web Form tag (Form1)
2. Login form (Login)
3. Google search form (Google)
4. PayPal form (PayPal)

2 through 4 are obviously embedded into the #1 form. On FireFox I notice
that one of the forms is not reported by the PageInfo dialog (very handy
tool). I reported it as a bug there but I wonder if this actually causes
problems with ASP.NET. Why? because when the order of my forms were 1, 4, 2,
3 and I had a user control that had a form as well (that would have been
just the ASP.NET web controls without FORM tag because it is always
contained in #1) then the "Submit" button would no longer work.

Strange... Now in the order shows above (1.2.3.4) the submit button works
(you can click and it posts back). Any ideas?

Thx
Emilio
 
S

Steve C. Orr [MVP, MCSD]

User controls should generally not contain Form tags, or else it causes
problems like you're describing.


Other details:
You can only have one visible server form on the page at a time.
So you could have more than one server form as long as you only show one at
a time.
Or you can have more than one form visible on your page at a time, but only
one of them can be a server form (i.e. with the runat=server attribute.)
Server forms only support posting back to themselves (not to other pages.)


This will all become more flexible in .NET version 2.
 
N

~~~ .NET Ed ~~~

Yes, actually I forgot to mention that only Form #1 was a server form
(runat), all the others are "regular" forms but are nested within the server
form. Would that cause problems as well?

The issue is that the "master" page contains the server form, within the
form there is an HTML table that splits the web form into 3 columns (left &
right navigation panel and mid content panel). There can be "applets" on the
left and right sides, these are simple regular forms (normal HTML forms),
but the whole thing is within the server form, only they don't have a runat
attribute.

Regards,
Emilio
 
S

Steve C. Orr [MVP, MCSD]

I don't believe the HTML specification supports nested forms.
Multiple forms are ok, but not inside eachother.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
 
N

~~~ .NET Ed ~~~

Then what would be the best way to handle it? it all has to do with how the
page functions:

+-------------------------------------------------------------------------------------+
| [HEADER]
|
+------------------+---------------------------------------------+--------------------+
| LEFT PANE | MIDDLE PANE
| RIGHT PANE |
| [Literal] |
| |
| [Form A] | Content
| [Literal] |
| | [Possibly some web controls]
| [Form B] |
| |
| [Form C] |
+------------------+---------------------------------------------+-------------------+
| F O O T E R
|
+--------------------------------------------------------------------------------------+

Form A: Login HTML form (not an ASP.NET form)
Form B: Google search form (not an ASP.NET form)
Form C: PayPal button form (not an ASP.NET form) <- UserControl

And then, HEADER is an ASP.NET composite control, and the two Literals, as
well as some
that *may* appear in the middle pane are the simple ASP.NET WebControls
(TextBox, Literal,
Button, radioButton, etc.). Because of that those need to be enclosed in the
ASP.NET server
form (form id="Form1").

I don't think ASP.NET is not able to handle this sort of layout which is not
complex at all and
since I cannot have multiple server forms I cannot regroup the literals and
the other web controls
to beginning or end without totally destroying the page layout.

As you can see, this is some sort of page template. Anyway suggestions are
appreciated.

Regards,
Emilio
 
M

Martin Eyles

Try making the middle pane a form run at the server, and put everything else
(including other forms) outside that form. You can still run other items
outside the form at the server, so you could dynamically change the header.

HTH, ME

--
Martin Eyles
(e-mail address removed)



~~~ .NET Ed ~~~ said:
Then what would be the best way to handle it? it all has to do with how the
page functions:

+---------------------------------------------------------------------------
----------+
| [HEADER]
|
+------------------+---------------------------------------------+----------
----------+
| LEFT PANE | MIDDLE PANE
| RIGHT PANE |
| [Literal] |
| |
| [Form A] | Content
| [Literal] |
| | [Possibly some web controls]
| [Form B] |
| |
| [Form C] |
+------------------+---------------------------------------------+----------
---------+
| F O O T E R
|
+---------------------------------------------------------------------------
-----------+

Form A: Login HTML form (not an ASP.NET form)
Form B: Google search form (not an ASP.NET form)
Form C: PayPal button form (not an ASP.NET form) <- UserControl

And then, HEADER is an ASP.NET composite control, and the two Literals, as
well as some
that *may* appear in the middle pane are the simple ASP.NET WebControls
(TextBox, Literal,
Button, radioButton, etc.). Because of that those need to be enclosed in the
ASP.NET server
form (form id="Form1").

I don't think ASP.NET is not able to handle this sort of layout which is not
complex at all and
since I cannot have multiple server forms I cannot regroup the literals and
the other web controls
to beginning or end without totally destroying the page layout.

As you can see, this is some sort of page template. Anyway suggestions are
appreciated.

Regards,
Emilio


Steve C. Orr said:
I don't believe the HTML specification supports nested forms.
Multiple forms are ok, but not inside eachother.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top