一个页面只能有一个服务器标签

时间:2013-12-17 08:18:35

标签: c# asp.net

我有一个母版页,但是当我运行shopcart页面时,它显示错误“一个页面只能有一个服务器端的Form标签”。我不知道要删除哪个runat 任何帮助将不胜感激,谢谢:)

这是我的母版代码

<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>
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
    <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>
            &nbsp
           <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>
            &nbsp
            <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>

这是我的shopCart页面的代码

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id= "form1" 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>

6 个答案:

答案 0 :(得分:1)

从ShopCart中的runat="server"标记中删除form 页。 您也可以从form页面删除shopcart代码,因为您的母版页已包含Form代码。

答案 1 :(得分:0)

您应该从form

中删除shopCart page标记

在ASP.NET模型中,单个服务器标签负责所有页面处理。

答案 2 :(得分:0)

您的购物车页面有

<form id= "form1" runat="server">

由于contentplaceholder已在表单中,因此不需要。 contentplaceholder的内容将添加到母版页。

答案 3 :(得分:0)

您不需要shopCart页面上的其他表单,因为您的母版页上有一个表单。母版页上的表单包含在使用母版页的每个页面上。所以我会从shopCart页面中删除以下标记;

<form id= "form1" runat="server">

答案 4 :(得分:0)

您需要删除子页面中的<form id= "form1" runat="server">

因为ContentPlaceHolder1已经在母版页中有表单标记了!

答案 5 :(得分:0)

更新您的购物车页面

<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>