asp.net错误形式不能嵌套元素表单内? [英] asp.net error form cannot be nested within element form?
问题描述
我在使用表单标签的asp.net应用程序有一个内容页。只有一个页面,所以我很困惑为什么它给我的错误上:验证(HTML5):元素形式不能嵌套元素形式
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'
继承人的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>
我有一个表格在我的母版但wasnt给我的问题..昨天
I have a form in my masterpage but that wasnt giving me problems yesterday..
任何想法?
推荐答案
如果你的&LT; ASP:的ContentPlaceHolder ID =日程地址搜索Maincontent&GT;
控制,本身里面一个格式
元素,那么你不应该放置格式
的 ASP内部:内容
控制,你不应该有嵌套的表格。
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.
从 HTML5 工作草案:
4.10.3的表单元素结果
内容模型:结果
流量的内容,但没有表单元素后裔。
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
更新
请参阅问题一页只能有一个服务器端Form标记:
母版页不应包含表单标签一般,因为他们是为了仅作为内容页面的基地布局。
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:
- 只添加
格式
元素aspx页面 - 主要内容
母版
从网页添加 - 添加需要被表单中嵌套任意内容
用户控件
被放置在页面中。
- 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.
这篇关于asp.net错误形式不能嵌套元素表单内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!