2

情况:我有一个母版页,它有 3 个内容占位符,但没有表单 runat 服务器。在我的 Login.aspx 中,我尝试填充这些占位符,但它不允许我没有表单 runat 服务器标签,一旦我再次添加多个表单,它会显示:“一个页面只能有一个服务器端表单标签。 "

这是我的代码:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="DWDS_Lotus_Care_Final.Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <form id="formUser" runat="server">
            <p>
                <asp:Label ID="lblUsername" runat="server" Text="Username"></asp:Label>
                <asp:Button ID="btnLogout" runat="server" Text="Logout" />
            </p>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form id="form1" runat="server">
    <table style="width: 100%">
        <tr>
            <td style="width: 93px">
                UserName :
            </td>
            <td style="width: 139px">
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            </td>
            <td style="width: 307px">
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtUserName" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td style="width: 93px">
                Password :</td>
            <td style="width: 139px">
        <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
            </td>
            <td style="width: 307px">
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtPassword" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td style="width: 93px">
                &nbsp;</td>
            <td style="width: 139px">
        <asp:Button ID="btnSubmit" Text="Submit" runat="server" 
            onclick="btnSubmit_Click" />
        &nbsp;&nbsp;
        <asp:Button ID="btnClear" Text="Clear" runat="server" 
            onclick="btnClear_Click" />
            </td>
            <td style="width: 307px">
        <asp:LinkButton ID="linkRegister" Text="Register" runat="server"></asp:LinkButton>
            </td>
        </tr>
    </table>
        </p>
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">

</asp:Content>

这是主要来源

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"     Inherits="DWDS_Lotus_Care_Final.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <title>Consistent</title>
    <link href="http://fonts.googleapis.com/css?family=Bitter" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
        <div id="wrapper">
        <div id="header">
            <div id="logo">

            </div>
        </div>
            <div id="menu">
                <ul>
                    <li><a href="#">Login</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Portfolio</a></li>
                    <li class="last"><a href="#">Contact</a></li>
                </ul>
            </div>
            <div id="page">



        <%--Here is the sidebar--%>
            <div id="sidebar" style="background-color:#CCCCCC">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
                </asp:ContentPlaceHolder>
                    <h3>Links to Other Hospitals</h3>
                    <div class="date-list">
                        <ul class="list date-list">
                            <li class="first"><span class="date">Sunway</span> <a href="#">Sunway Piramid</a></li>
                            <li><span class="date">KPJ</span> <a href="#">Kajang Care Centre</a></li>
                            <li><span class="date">HCC</span> <a href="#">Health Care Center</a></li>
                            <li><span class="date">AlphaH</span> <a href="#">Alpha Health Center</a></li>
                            <li><span class="date">UPC</span> <a href="#">Bangsar Hospital</a></li>
                            <li class="last"><span class="date">TPM</span> <a href="#">Technology Park Hospital</a></li>
                        </ul>
                    </div>
                <br class="clearfix" />
            </div>



            <%--Here is the Content--%>
            <div id="content">
                <h2>Welcome to Lotus Care</h2>

                <div class="box">
                     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

                     </asp:ContentPlaceHolder>
                </div>
                <div class="box">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">

                     </asp:ContentPlaceHolder>
                </div>
                <br class="clearfix" />
            </div>





            <br class="clearfix" />
        </div>
    </div>
    <div id="footer">
        </div>
</body>

4

3 回答 3

2

母版页:

<form runat="server">
   <%-- use form tag only in Master page.--%>
 <div id="content">
 <h2>Welcome to Lotus Care</h2>
 <div class="box">
  <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

  </asp:ContentPlaceHolder>
  </div>
  <div class="box">
  <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">

  </asp:ContentPlaceHolder>
  </div>
  <br class="clearfix" />
 </div>
</form>

内容页:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <%-- don't use Form tag here..--%>
  <table style="width: 100%">
  </table>
</asp:Content>
于 2012-05-03T07:40:46.333 回答
1

这就是我所做的:

对于这种情况,我将使用 div 或面板

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<div>
//Place some controls here    
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
//Put some controls here 
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
<div>
//Put some more controls here
</div>
</asp:Content>
于 2012-05-03T07:27:06.290 回答
0

在 VS2017 中,你可以使用没有表单标签的 contentplaceholder。使用 asp.net 4.6.2

于 2017-05-12T07:17:58.787 回答