如何避免嵌套表单的情况?

How can I avoid a nested form situation?

好的,基本上我有一个母版页,其中包含带有 runat 服务器的表单中的所有设计,如下所示:

<head runat="server">
  <title></title>
  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
</head>
<body>
  <form id="form1" runat="server">

    <table style="font-family: Arial">
      <tr>
        <td colspan="2" style="width: 800px; height: 80px; background-color: #3399FF; text-align: center">
          <h1>WebSite Header
          </h1>
        </td>
      </tr>
      <tr>
        <td style="height: 500px; background-color: #66FFFF; width: 150px">
          <h3>Menu</h3>
        </td>
        <td style="height: 500px; background-color: #9999FF; width: 650px">
          <h3>content</h3>
          <div>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
              <p>
                &nbsp;</p>
            </asp:ContentPlaceHolder>
          </div>
        </td>
      </tr>
      <tr>
        <td colspan="2" style="background-color: #3399FF; text-align: center">
          <b>Website Footer</b>
        </td>
      </tr>
    </table>


  </form>
</body>
</html>

现在我正在尝试使用这个母版页做一个页面,在这个页面中我正在初始化一个 CKEditor,它显然需要以具有 runat 服务器的形式才能运行,如下所示:

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

<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

  <form id="form2" runat="server">
    <div>
      <div>
        <CKEditor:CKEditorControl ID="CKEditor1" runat="server">
        </CKEditor:CKEditorControl>
      </div>
      <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
      <asp:Label ID="lblText" runat="server" Text=" "></asp:Label>
    </div>
  </form>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

然而,其中包含 CKEditor 的表单不允许初始化,因为它正在成为一个嵌套表单,因为母版页本身绑定在一个表单中。

请问我该如何预防?

您的 CKEditorControl 将从母版页继承表单。

首先,将您的 asp:ContentPlaceHolderhead 标签中移出:

<head runat="server">
<title></title>
<!--DON'T PUT IT HERE-->
</head>
<body>
   <form id="form1" runat="server">
      <asp:ContentPlaceHolder ID="head" runat="server">
      </asp:ContentPlaceHolder>
...

现在您可以删除 form2:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<!--<form id="form2" runat="server">-->
  <div>
    <div>
      <CKEditor:CKEditorControl ID="CKEditor1" runat="server">
      </CKEditor:CKEditorControl>
...