【问题标题】:A page can only have one server tag一个页面只能有一个服务器标签
【发布时间】:2013-12-17 16:44:31
【问题描述】:

我有一个母版页,但是当我运行购物车页面时,它显示错误“一个页面只能有一个服务器端表单标签”。我不知道要删除哪个 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>

这是我的购物车页面的代码

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

【问题讨论】:

  • 您有多个带有runat="server" 属性的Form 标签。在母版页中使用单个 &lt;form runat="server"&gt; 并将所有内容放在该表单标记下
  • 只在包含主要占位符的表单上使用 runat="server"。
  • 删除购物车页面中的表单标签,因为母版页有表单标签,您在使用母版页的页面中不需要它。

标签: c# asp.net


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您应该从shopCart page 中删除form 标签

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

    【讨论】:

      【解决方案3】:

      您的购物车页面有

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

      这不是必需的,因为内容占位符已经在表单中。 contentplaceholder 的内容将被添加到母版页。

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          【解决方案5】:

          您需要在子页面中删除&lt;form id= "form1" runat="server"&gt;

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

          【讨论】:

            【解决方案6】:

            更新您的购物车页面

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

            【讨论】:

              猜你喜欢
              • 2011-08-16
              • 1970-01-01
              • 2011-02-24
              • 2014-12-07
              • 2020-05-26
              • 1970-01-01
              • 2012-08-29
              相关资源
              最近更新 更多