Nested Forms in ASP.NET

Discussion in 'ASP .Net' started by ~~~ .NET Ed ~~~, Dec 13, 2004.

  1. 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
     
    ~~~ .NET Ed ~~~, Dec 13, 2004
    #1
    1. Advertising

  2. 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.


    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net
    Hire top-notch developers at http://www.able-consulting.com



    "~~~ .NET Ed ~~~" <> wrote in message
    news:O$...
    > 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
    >
     
    Steve C. Orr [MVP, MCSD], Dec 13, 2004
    #2
    1. Advertising

  3. 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

    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:%...
    > 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.
    >
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://Steve.Orr.net
    > Hire top-notch developers at http://www.able-consulting.com
    >
    >
    >
    > "~~~ .NET Ed ~~~" <> wrote in message
    > news:O$...
    >> 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
    >>

    >
    >
     
    ~~~ .NET Ed ~~~, Dec 14, 2004
    #3
  4. 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


    "~~~ .NET Ed ~~~" <> wrote in message
    news:...
    > 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
    >
    > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > news:%...
    >> 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.
    >>
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr, MCSD, MVP
    >> http://Steve.Orr.net
    >> Hire top-notch developers at http://www.able-consulting.com
    >>
    >>
    >>
    >> "~~~ .NET Ed ~~~" <> wrote in message
    >> news:O$...
    >>> 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
    >>>

    >>
    >>

    >
    >
     
    Steve C. Orr [MVP, MCSD], Dec 14, 2004
    #4
  5. 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 [MVP, MCSD]" <> wrote in message
    news:...
    >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
    >
    >
    > "~~~ .NET Ed ~~~" <> wrote in message
    > news:...
    >> 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
    >>
    >> "Steve C. Orr [MVP, MCSD]" <> wrote in message
    >> news:%...
    >>> 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.
    >>>
    >>>
    >>> --
    >>> I hope this helps,
    >>> Steve C. Orr, MCSD, MVP
    >>> http://Steve.Orr.net
    >>> Hire top-notch developers at http://www.able-consulting.com
    >>>
    >>>
    >>>
    >>> "~~~ .NET Ed ~~~" <> wrote in message
    >>> news:O$...
    >>>> 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
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    ~~~ .NET Ed ~~~, Dec 14, 2004
    #5
  6. ~~~ .NET Ed ~~~

    Martin Eyles Guest

    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




    "~~~ .NET Ed ~~~" <> wrote in message
    news:...
    > 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 [MVP, MCSD]" <> wrote in message
    > news:...
    > >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
    > >
    > >
    > > "~~~ .NET Ed ~~~" <> wrote in message
    > > news:...
    > >> 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
    > >>
    > >> "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > >> news:%...
    > >>> 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.
    > >>>
    > >>>
    > >>> --
    > >>> I hope this helps,
    > >>> Steve C. Orr, MCSD, MVP
    > >>> http://Steve.Orr.net
    > >>> Hire top-notch developers at http://www.able-consulting.com
    > >>>
    > >>>
    > >>>
    > >>> "~~~ .NET Ed ~~~" <> wrote in message
    > >>> news:O$...
    > >>>> 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
    > >>>>
    > >>>
    > >>>
    > >>
    > >>

    > >
    > >

    >
    >
     
    Martin Eyles, Dec 14, 2004
    #6
  7. ~~~ .NET Ed ~~~

    br00t

    Joined:
    May 21, 2007
    Messages:
    1
    br00t, May 21, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Virgil Hobbs
    Replies:
    0
    Views:
    545
    David Virgil Hobbs
    Jan 6, 2004
  2. jlopes151
    Replies:
    2
    Views:
    692
    Steve C. Orr [MVP, MCSD]
    Mar 14, 2005
  3. =?Utf-8?B?SmltUQ==?=

    ASP.Net tabel nested in another ASP.Net table

    =?Utf-8?B?SmltUQ==?=, Mar 23, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,814
    =?Utf-8?B?SmltUQ==?=
    Mar 23, 2007
  4. Toni Pohl
    Replies:
    1
    Views:
    982
    Toni Pohl
    Aug 10, 2008
  5. Eric
    Replies:
    2
    Views:
    648
Loading...

Share This Page