Getting a "normal" HTML form to work inside the server-side form tag

Discussion in 'ASP .Net' started by Deane, Jul 30, 2007.

  1. Deane

    Deane Guest

    I've run into this problem on many occasions --

    I need to have the server side form tag on my Web form, of course.

    But I also need to have *another* form on the page that posts to a URL
    totally out of my control. I can think of three situations off the
    top of my head.

    In one case, it was a login to the client's PeopleSoft system.
    In another, it was a PayPal form.
    In another, the form posted to the client's Google Mini install.

    What's the solution for this? I haven't found a good one yet. How do
    you get a "traditional" (non server-side) HTML form to work within the
    server-side form tag?
     
    Deane, Jul 30, 2007
    #1
    1. Advertising

  2. A form cannot be within another form. This is against the rules of HTML.
    You can have more than one form as long as one of them is a "traditional"
    (non server-side) HTML form as you've specified. Just don't nest them.
    Make sure there is no runat="server" attribute for your traditional HTML
    form.

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




    "Deane" <> wrote in message
    news:...
    > I've run into this problem on many occasions --
    >
    > I need to have the server side form tag on my Web form, of course.
    >
    > But I also need to have *another* form on the page that posts to a URL
    > totally out of my control. I can think of three situations off the
    > top of my head.
    >
    > In one case, it was a login to the client's PeopleSoft system.
    > In another, it was a PayPal form.
    > In another, the form posted to the client's Google Mini install.
    >
    > What's the solution for this? I haven't found a good one yet. How do
    > you get a "traditional" (non server-side) HTML form to work within the
    > server-side form tag?
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jul 30, 2007
    #2
    1. Advertising

  3. Deane

    Brandon Gano Guest

    Forms cannot be nested, so there is no way to have a client-side form inside
    a server-side form. There are a couple other options that might work for
    you, though.

    1) Don't nest the forms. Only server-side controls need to be contained
    within a <form runat="server" /> tag. If all of your server-side controls
    are above or below the client-side form, you can do something like:

    <html>
    <body>
    <form runat="server">
    ...
    </form>
    <form action="...">
    ...
    </form>
    </body>
    </html>

    2) The other option requires the use of JavaScript to change the forms
    action when you click a link/button. Something like (not tested):

    <html>
    <head>
    <script type="text/javascript">
    function SubmitForm()
    {
    var form = document.getElementById('MyForm');
    if (form)
    {
    form.action = 'new/url';
    form.submit();
    }
    }
    </script>
    </head>
    <body>
    <form runat="server">
    ...
    <input type="submit" value="Click" onclick="JavaScript: SubmitForm();" />
    </form>
    </body>
    </html>

    3) There is also a way to set the server-side form to post back to a
    different URL. I don't recall the syntax to do that, but I'm sure someone
    else in the group can help there.


    "Deane" <> wrote in message
    news:...
    > I've run into this problem on many occasions --
    >
    > I need to have the server side form tag on my Web form, of course.
    >
    > But I also need to have *another* form on the page that posts to a URL
    > totally out of my control. I can think of three situations off the
    > top of my head.
    >
    > In one case, it was a login to the client's PeopleSoft system.
    > In another, it was a PayPal form.
    > In another, the form posted to the client's Google Mini install.
    >
    > What's the solution for this? I haven't found a good one yet. How do
    > you get a "traditional" (non server-side) HTML form to work within the
    > server-side form tag?
    >
     
    Brandon Gano, Jul 30, 2007
    #3
  4. Deane

    Deane Guest

    Sadly, it appears that I'm thoroughly screwed here.

    I have server-side controls both above and below where this other HTML
    form needs to go. So the whole thing needs to go in a server-side
    form tag. And you can't have more than one server-side form tag, so
    it's not like I can "shut it off," do the normal form, then turn it
    back on again.

    Ideas?



    On Jul 30, 4:10 pm, "Brandon Gano" <> wrote:
    > Forms cannot be nested, so there is no way to have a client-sideforminside
    > a server-sideform. There are a couple other options that might work for
    > you, though.
    >
    > 1) Don't nest the forms. Only server-side controls need to be contained
    > within a <formrunat="server" /> tag. If all of your server-side controls
    > are above or below the client-sideform, you can do something like:
    >
    > <html>
    > <body>
    > <formrunat="server">
    > ...
    > </form>
    > <formaction="...">
    > ...
    > </form>
    > </body>
    > </html>
    >
    > 2) The other option requires the use of JavaScript to change the forms
    > action when you click a link/button. Something like (not tested):
    >
    > <html>
    > <head>
    > <script type="text/javascript">
    > function SubmitForm()
    > {
    > varform= document.getElementById('MyForm');
    > if (form)
    > {
    > form.action = 'new/url';
    > form.submit();
    > }
    > }
    > </script>
    > </head>
    > <body>
    > <formrunat="server">
    > ...
    > <input type="submit" value="Click" onclick="JavaScript: SubmitForm();" />
    > </form>
    > </body>
    > </html>
    >
    > 3) There is also a way to set the server-sideformto post back to a
    > different URL. I don't recall the syntax to do that, but I'm sure someone
    > else in the group can help there.
    >
    > "Deane" <> wrote in message
    >
    > news:...
    >
    > > I've run into this problem on many occasions --

    >
    > > I need to have the server sideformtag on my Webform, of course.

    >
    > > But I also need to have *another*formon the page that posts to a URL
    > > totally out of my control. I can think of three situations off the
    > > top of my head.

    >
    > > In one case, it was a login to the client's PeopleSoft system.
    > > In another, it was a PayPalform.
    > > In another, theformposted to the client's Google Mini install.

    >
    > > What's the solution for this? I haven't found a good one yet. How do
    > > you get a "traditional" (non server-side) HTMLformto work within the
    > > server-sideformtag?
     
    Deane, Aug 1, 2007
    #4
    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. RC
    Replies:
    2
    Views:
    445
    Malte
    May 10, 2005
  2. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  3. RC
    Replies:
    2
    Views:
    667
  4. André
    Replies:
    2
    Views:
    760
    André
    Jun 23, 2008
  5. Kiran More
    Replies:
    2
    Views:
    326
    Kiran More
    Nov 14, 2006
Loading...

Share This Page