1

I have an asp.net page with a nested master page. Parent master page has form tag like this:

 <form runat="server">
 ...
 ....
 </form>

and in child master page. I have a side bar where I have another form ( not runat=server") like this:

<form method="post" action="https://app.icontact.com/icp/signup.php" name="icpsignup" id="icpsignup3297" accept-charset="UTF-8" onsubmit="return verifyRequired3297();" >

<input type="hidden" name="redirect" value="http://www.abconline.com/newsletter-sign-up.aspx">
<input type="hidden" name="errorredirect" value="http://www.icontact.com/www/signup/error.html">

....
....
....
<input type="submit" name="Submit" value="Get Deals">
</form>

<script type="text/javascript">

    var icpForm3297 = document.getElementById('icpsignup3297');

    if (document.location.protocol === "https:")

        icpForm3297.action = "https://app.icontact.com/icp/signup.php";
    function verifyRequired3297() {
        if (icpForm3297["fields_email"].value == "") {
            icpForm3297["fields_email"].focus();
            alert("The Email field is required.");
            return false;
        }


        return true;
    }
</script>

but when I hit submit button, post back happens but javascript function is not called and form is not redirected to post url of child master page. It works fine if i use this form in a standalone page without master pages.

Please suggest how to force form inside child master page to go to post URL ?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316
  • Although not an exact duplicate, maybe you can find something useful in this question: http://stackoverflow.com/questions/2392238/can-i-have-one-form-tag-inside-another-in-asp-net-mvc-rc2 – Gerald Versluis Jul 20 '12 at 06:50
  • His question is not related with MVC – Jupaol Jul 20 '12 at 06:50

2 Answers2

3

As per HTML standards you cannot have nested forms i.e. form inside form. How ever you can create another content place holder in your master page outside the form tag then you can use forms in your child page. like this:

In your master page:

<form>
----
----
</form>

<asp:ContentPlaceHolder id="cp2" runat="server">

</asp:ContentPlaceHolder>

In your child page add form in this tag:

<asp:Content ID="Content3" ContentPlaceHolderID="cp2" Runat="Server">
</asp:Content>
0

See Quentin's answer here. Per HTML standards you cannot embed forms inside one another. Most browser's will ignore the inner form if you do.

Best solution would be to create an additional asp:Content on the master page where you can put secondary forms.

You can cascade the asp:Content from the base master page:

<!-- on base master page -->
<form runat="server" ...>
    main content here
</form>

<asp:ContentPlaceHolder runat="server" ID="SecondaryFormContentBase"></asp:ContentPlaceHolder>


<!-- on child master page -->
<asp:Content ID="Content1" ContentPlaceHolderID="SecondaryFormContentBase" Runat="server">
    <asp:ContentPlaceHolder runat="server" ID="SecondaryFormContent"></asp:ContentPlaceHolder>
</asp:Content>
Community
  • 1
  • 1
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
  • If I create another asp.net contentplaceholder in child master page, then I need to make sure that this contentplaceholder is not inside the form tag of parent master page ? or it can be inside the parent master page's form tag and still i can add a form in child master page and it will work ? – DotnetSparrow Jul 20 '12 at 07:08
  • It needs to be outside the any form tags, otherwise the rendered HTML will end up with an embedded form tag (the exact problem we're trying to avoid). – just.another.programmer Jul 20 '12 at 07:10
  • but my problem is that page is structured in such a way that base master page has a form then a ContentPlaceHolder, child master page overrides this ContentPlaceHolder by putting its own content. I am putting my form inside this ContentPlaceHolder which is overridden by child master page. – DotnetSparrow Jul 20 '12 at 07:13
  • So create a cascaded contentplaceholder going down to the child master page. I've edited my answer with details. – just.another.programmer Jul 20 '12 at 07:15