C# 一个页面只能有一个服务器标记
我有一个母版页,但当我运行shopcart页面时,它会显示错误“一个页面只能有一个服务器端表单标签”。我不知道该删除哪个runat 如有任何帮助,将不胜感激:) 这是我的母版页代码C# 一个页面只能有一个服务器标记,c#,asp.net,C#,Asp.net,我有一个母版页,但当我运行shopcart页面时,它会显示错误“一个页面只能有一个服务器端表单标签”。我不知道该删除哪个runat 如有任何帮助,将不胜感激:) 这是我的母版页代码 <asp:ContentPlaceHolder ID="headersContainer" runat="server" /> <div id="container"> <div id="header"> <div class="clear"><
<asp:ContentPlaceHolder ID="headersContainer" runat="server" />
<div id="container">
<div id="header">
<div class="clear"></div>
</div>
<div id="nav">
<ul>
<li ><a href="index.html">Home</a></li>
<li><a href="examples.html">Orders</a></li>
<li><a href="#">Cart</a></li>
<li><a href="#">Shipment</a></li>
</ul>
</div>
<div id="body">
<div id="content">
<div style= "text-align:right";>
<form runat="server">
<asp:Button ID="Button1" runat="server" Text="Items in Shopping Cart" BackColor="#FF531A"
BorderStyle="Dotted" CausesValidation="False" ForeColor="White"
Font-Bold /></form></div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" >
</asp:ContentPlaceHolder>
</div>
       
<div class="sidebar">
<ul>
<li>
<h3>User</h3>
<ul class="blocklist">
<li><a href="index.html">Register</a></li>
<li><a href="examples.html">Login</a></li
</ul>
</li>
 
<li>
<h3>Categories</h3>
<ul>
<li><a href="http://www.themeforest.net/?ref=spykawg" ><strong>Gadgets</strong></a></li>
<li><a href="http://www.dreamhost.com/r.cgi?259541" ><strong>Accessories</strong></a> </strong></li>
</ul>
</li>
 
<li>
<h3>Search</h3>
<ul>
<li>
<form method="get" class="searchform" action="http://wpdemo.justfreetemplates.com/" >
<p>
<input type="text" size="12" value="" name="s" class="s" />
<input type="submit" class="searchsubmit formbutton" value="Search" />
</p>
</form>
</li>
</ul>
</li>
</ul>
</div>
从购物车的表单中删除runat=“server”
页
您也可以从购物车
页面删除表单
标签,因为您的母版页已经包含表单
标签。您应该从购物车页面删除表单
标签
在ASP.NET模型中,单个服务器标记负责所有页面处理。您的购物车页面具有
<form id= "form1" runat="server">
这不是必需的,因为contentplaceholder已在表单中。contentplaceholder的内容将添加到母版页 在shopCart页面上不需要其他表单,因为母版页上有一个表单。母版页上的表单包含在使用母版页的每个页面上。因此,我将从shopCart页面删除以下标记
<form id= "form1" runat="server">
您需要删除子页面中的
因为contentplaceholder 1
在母版页中已经有表单标记 更新您的购物车页面
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" >
</asp:DropDownList>
<br />
<br />
<asp:GridView ID="grdCatalogue" runat="server" AutoGenerateColumns="False"
Width ="100px" onselectedindexchanged="grdCatalogue_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" >
<ControlStyle Width="80px" />
<FooterStyle Width="80px" />
<HeaderStyle Width="80px" />
<ItemStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
<asp:BoundField DataField="UserName" HeaderText="Sold By" />
<asp:BoundField DataField="Date" HeaderText="Date Uploaded" />
<asp:ImageField DataImageUrlField="Image1FileName"
DataImageUrlFormatString="~/Image/{0}" HeaderText="Image">
</asp:ImageField>
<asp:CommandField ButtonType="Button" HeaderText="Add to Cart"
ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
您有多个带有runat=“server”
属性的表单
标记。在母版页中使用单个
,并将所有内容放在该表单标记下,仅在包含主占位符的表单上使用runat=“server”。在shopCart页面中删除表单标记,因为母版页具有表单标记,而在使用母版页的页面中不需要它。
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" >
</asp:DropDownList>
<br />
<br />
<asp:GridView ID="grdCatalogue" runat="server" AutoGenerateColumns="False"
Width ="100px" onselectedindexchanged="grdCatalogue_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" >
<ControlStyle Width="80px" />
<FooterStyle Width="80px" />
<HeaderStyle Width="80px" />
<ItemStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
<asp:BoundField DataField="UserName" HeaderText="Sold By" />
<asp:BoundField DataField="Date" HeaderText="Date Uploaded" />
<asp:ImageField DataImageUrlField="Image1FileName"
DataImageUrlFormatString="~/Image/{0}" HeaderText="Image">
</asp:ImageField>
<asp:CommandField ButtonType="Button" HeaderText="Add to Cart"
ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>