Asp.net error form cannot be nested in element form?

I have a content page in an asp.net application that uses a form tag. There is only one on the page, so I got confused why it gave me an error: Validation (HTML5): The 'form' element should not be nested in the 'form' element

Here is 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 on my main page, but yesterday it did not give me problems.

Any ideas?

+6
source share
1 answer

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

From HTML5 working draft:

4.10.3 Form Element
Content Model:
The content of the stream, but without descendants of the form element.

UPDATE

See question. A page can have only one form tag on the server side :

Main pages should not contain form tags at all, as they are intended to be used only as the base layout of your content page.

Try restructuring the project using the following guidelines:

  • Add only form tags to aspx pages
  • Add main content to MasterPage from pages
  • Add any content that should be attached to the form on UserControl , which is placed inside the page.
+7
source

Source: https://habr.com/ru/post/951236/


All Articles