Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net error form cannot be nested within element form?

Tags:

forms

asp.net

I have a content page in an asp.net application that uses a form tag. There's only one on the page so I'm confused why its give me the error: Validation (HTML5): Element 'form' must not be nested within element 'form'

Heres the code:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="Default.aspx.cs" Inherits="WebApplication6._Default" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
   <div>
      <form id="form1">
         <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
               <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
               <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
               <asp:BoundField DataField="Director" HeaderText="Director" SortExpression="Director" />
               <asp:BoundField DataField="DateReleased" HeaderText="DateReleased" SortExpression="DateReleased" />
               <asp:TemplateField HeaderText="Selection">
                  <ItemTemplate>
                     <asp:CheckBox ID="Selections" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged1" />
                  </ItemTemplate>
               </asp:TemplateField>
            </Columns>
         </asp:GridView>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Movies]"></asp:SqlDataSource>
         <asp:Button ID="Button1" runat="server" Text="Select Movies" OnClick="Button1_Click" CausesValidation="False" />
         <asp:TextBox ID="TextBox1"  Text="First Name" runat="server"></asp:TextBox>
      </form>
   </div>
</asp:Content>

I have a form in my masterpage but that wasnt giving me problems yesterday..

Any ideas?

like image 676
Will Tuttle Avatar asked Aug 07 '13 16:08

Will Tuttle


1 Answers

If your <asp:ContentPlaceHolder ID="MainContent" > control is, itself, inside of a form element, then you shouldn't place a form inside of the asp:content control as you should not have nested forms.

From the HTML5 working draft:

4.10.3 The form element
Content model:
Flow content, but with no form element descendants.

UPDATE

See the question A page can have only one server-side Form tag:

Master pages should not contain form tags in general because they are meant to be used only as the base layout of your content page.

Try to restructure your project using these guidelines:

  • Only add form elements to aspx pages
  • Add main content to MasterPage from pages
  • Add any content that needs to be nested within a form to a UserControl that is placed within a page.
like image 139
KyleMit Avatar answered Oct 09 '22 01:10

KyleMit