繁体   English   中英

ASP.net联系我们页面

[英]ASP.net Contact us page

这是一个非常简单的问题,因为我是asp.net的新手我正在尝试开发一个联系我们页面,我收到以下错误。

“类型'TextBox'的控件'ContentPlaceHolder1_nameBox'必须放在带有runat = server的表单标签内”

以下是我目前为该页面的代码。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="ContactUs.aspx.cs" Inherits="Craigavon_Aquatics.ContactUs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<h2>
    Contact Us</h2>
<p>
    Please fill in the form below to contact us.</p>

<p>
    &nbsp;</p>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table style="width: 100%">
    <tr>
        <td>
            Name: (Required)</td>
    </tr>
    <tr>
        <td>
<asp:TextBox ID="nameBox" runat="server" Width="278px"></asp:TextBox>                
        </td>
    </tr>
    <tr>
        <td>
            Email: (Required)</td>
    </tr>
    <tr>
        <td>

        </td>
    </tr>
</table>
</asp:Content>

在包含contentplaceholder的主页中放置一个包装器<form runat="Server"> ,或者在<asp:Content>标签内的该页面上添加一个围绕当前内容的<form runat="server">

Site1.Master

<form runat="server">
  <asp:ContentPlaceHolder ...></asp:ContentPlaceHolder>
</form>

-要么-

ContactUs.aspx

<asp:Content ...>
  <form runat="server">
    ...existing HTML code...
  </form>
</asp:Content>

找到ID为'ContentPlaceHolder1_nameBox'的控件,并放在.aspx的表单/表单标签之间以消除错误。 ASP .Net Server控件必须位于Form标签内。

你需要<form runat="server"> //你的代码,控件.. </form>标签来包围你的代码。 这可能是您的母版页中遗漏的

您必须检查并确保在母版页上声明了一个表单。 因为我看不到,所以我不得不假设如果出现错误就没有。

最简单的解决方案是将主体包裹在MasterPage中。
但你也可以像这样覆盖它。

public override void VerifyRenderingInServerForm(Control control) 
{
    return;
}

母版页中的所有控件都应位于<form>...</form>标记内,包括内容占位符。

这与“联系页面”无关。 这通常是ASP.NET页面的基础。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM