Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikael Mørup 297 posts 326 karma points
    Sep 14, 2009 @ 15:06
    Mikael Mørup
    0

    Multiple forms in templates ?

    I have a master template with a form tag with runat="server", and a sub template with another form tag, like shown here:

    Master template (only a fraction shown here):


    <form id="test" runat="server">

        <asp:ContentPlaceHolder Id="MasterPlaceholder" runat="server">
        
        <!-- sub template inserted here -->

        </asp:ContentPlaceHolder>
    </form>


    Sub template (only a fraction shown here) :


    <form id="Form" action="http://localhost/xxx.aspx" method="get">


    </form>

     

    When clicking the submit button belonging to the form in the subtemplate, nothing happens, except the page is reloaded, i would have expected that i was sent to the xxx.aspx page.

    Is it wrong to have two nested forms like this ?

    If so, is there a workaround ?

    Thanks

    Mikael

     

  • dandrayne 1138 posts 2262 karma points
    Sep 14, 2009 @ 15:58
    dandrayne
    0

    Id only insert the first <form id="test" runat="server"> around where it is needed (such as a contact form macro etc).  Forms cant be nested, so I dont think there's another workaround

  • Sjors Pals 617 posts 270 karma points
    Sep 14, 2009 @ 16:51
    Sjors Pals
    0

    Just remove the second form, if there is one in your Mastertemplate you don't need a second one, you can create different handlers for different submits.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Sep 14, 2009 @ 17:02
    Nik Wahlberg
    0

    If you need to subit your form to another URL (other than a PostBack) look into using PostBackUrl on the button. As mentioned, multiple forms are not allowed (at least not nested). Or, you might be able to use GET instead of POST to pass your attribute values.

    Hope this helps,
    Nik

  • Mikael Mørup 297 posts 326 karma points
    Sep 14, 2009 @ 21:23
    Mikael Mørup
    0

    My problem is that the first form is there because i have some .NET user controls that need it, with runat= server, the second form is there because i have a bunch of request query variables i post to another form.

    Maybee the best solution is to make a template for the post back form that is independend of the mastertemplate ? Which would be a shame as they share a common top navigation bar and a footer section.

    Mikael

     

  • Chris Koiak 700 posts 2626 karma points
    Sep 14, 2009 @ 21:41
    Chris Koiak
    1

    Why not remove the runat server form completely?

    You can add it on the templates that require it.

     

  • Mikael Mørup 297 posts 326 karma points
    Sep 14, 2009 @ 22:01
    Mikael Mørup
    0

    Thanks for that suggestion, i will try that.

    Mikael

  • Ron Brouwer 273 posts 768 karma points
    Sep 14, 2009 @ 22:08
    Ron Brouwer
    0

    I also would like to know how this can be fixed.
    I've created a lot of different workarounds but non of those work the way they should.

    When I need to post something to different site (for mailing subscription or payment) this causes a big problem. When you want to use inline editing or let the webeditor control where forms are placed on the website there is no way to get around the form runat server on the mastertemplate.

    Is there anyone who can give a good solution that does not require javascript?

    Thanks,

    Ron

  • Chris Koiak 700 posts 2626 karma points
    Sep 14, 2009 @ 23:47
    Chris Koiak
    0

    This only proper approach is to have separate forms. This is one of the great things about Umbraco... you don't need a runatserver form.

    You can include a runatserver form in your userControl macro if you need to.... just don't put it on the template!

    Chris

  • Mikael Mørup 297 posts 326 karma points
    Sep 15, 2009 @ 07:51
    Mikael Mørup
    0

    I just did a Chris suggested - removing the form needed by the usercontrols from the master template and putting it only in the templates where it's needed, that solves my problem for now.

     

    The problem with putting the runatserver form on the user control comes if you have more than one control or multiple instances of the same control on a page. You can only have one run at form on a page!

  • Ron Brouwer 273 posts 768 karma points
    Sep 15, 2009 @ 08:40
    Ron Brouwer
    0

    @Chris I don't agree with you. What if i have a search control on all pages or want to use canvasediting and they both require a runat server form. Then when I need to post some data to another webapplication, your solution does not work.

    How would you solve that problem?

    Ron

  • Chris Koiak 700 posts 2626 karma points
    Sep 15, 2009 @ 10:33
    Chris Koiak
    0

    You can't without JS.

    Your search control can be a standard html form, it doesn't need to use ASP.NET TextBox.

    I don't use Canvas, if I did then I would inject in the Form control on page init. This would therefore only include the server Form when required. You'd have to be careful to avoid your search form, in the control collection, if it's also present.

    You could always take Nik's suggestion above, and use PostBackUrl (see http://msdn.microsoft.com/en-us/library/ms178140.aspx). However this will just add JS to accomplish what html is built to support.

    Cheers,

    Chris

  • Ron Brouwer 273 posts 768 karma points
    Sep 15, 2009 @ 12:09
    Ron Brouwer
    0

    So basicly there is no proper solution available in .NET at this time.

    Thats unfortunate..

    Ron

  • Chris Koiak 700 posts 2626 karma points
    Sep 15, 2009 @ 14:26
    Chris Koiak
    0

    ASP.NET forms are designed to always post back to the originating url, this is by design and the proper approach in ASP.NET forms. Unfortunately it's leads to the restrictions you mention. Any pure JS approach to solving this always feels a little wrong.

    A big benefit to Umbraco is that it doesn't enforce a server form in your presentation.

    In general though, thankfully we now have ASP.NET MVC. IMO - One of the advantages and purposes to ASP.NET MVC is to remove this restriction and go back to more fundemental html standards.

    Chris

     

  • Mikael Mørup 297 posts 326 karma points
    Oct 09, 2009 @ 14:44
    Mikael Mørup
    0

    Oh yes. This thing hit me in the back of my head like a boomerang.

    Now i want to do exactly what Ron suggest, have a search control on all pages in other words, in my master template. So now my solution where i removed the form runat=server tag out of my master template and put it in the sub template that really needed it does no longer work.

    So it looks like the only solution is to not let the subtemplates that uses form runat=server tag inherit from the mastertemplate, which mean having the same stuff to maintain in two sets of templates.

    Oh my - how i wish there was a solution to this problem.

    Mikael

  • Elena 8 posts 29 karma points
    Oct 13, 2009 @ 23:08
    Elena
    0

    you can have only one asp.net form on the page - but as many html forms as u like. create the other search boxes as a html form with a action to the desired search page and choose between post/get. read the vars on the destination page and do the search there.

    cheers

    El

  • Elena 8 posts 29 karma points
    Oct 13, 2009 @ 23:10
    Elena
    0

    ups don't forget allthought you can have nested forms try not to do that since it can confuse the css

     

  • Mikael Mørup 297 posts 326 karma points
    Oct 14, 2009 @ 09:48
    Mikael Mørup
    0

    A couple of days ago i solved the problem by doing exactly as Elena suggests.

    I think a similar approach was suggested eralier in the thread, i just didn't understand it :-)

    reading this <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:612.0pt 792.0pt; margin:3.0cm 2.0cm 3.0cm 2.0cm; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> http://msdn.microsoft.com/en-us/magazine/cc163736.aspx

    was enligthening

    Thanks to all

    Mikael


  • Mikael Mørup 297 posts 326 karma points
    Oct 14, 2009 @ 10:07
    Mikael Mørup
    0

    wow did i do that ??

Please Sign in or register to post replies

Write your reply to:

Draft