开发者

ASP.net Contact us page

This is a pretty simple question as i am new to asp.net i am trying to develop a contact us page and i am getting the following error.

"Control 'ContentPlaceHolder1_nameBox' of type 'TextBox' must be placed inside a form tag with runat=server"

The following is my code so far for that page.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="ContactUs.aspx.cs" Inherits="Craigavon_Aq开发者_如何学Cuatics.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>


Either place a wrapper <form runat="Server"> in your master page around the contentplaceholder, or on that page inside the <asp:Content> tag add a <form runat="server"> that surrounds your current content.

Site1.Master

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

-OR-

ContactUs.aspx

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


Find the control with the ID of 'ContentPlaceHolder1_nameBox' and place in between the .aspx's form /form tags to get rid of the error. ASP .Net Server controls have to be within the Form tags.


You need <form runat="server"> // your code, controls .. </form> tag to surround your code. this is probably missing from your master page


You would have to check and make sure that you have a form declared on the master page. Since I can't see that, then I would have to assume that there isn't one if that error is coming up.


The simplest solution is to wrap the body inside at your MasterPage.
But you could also override it like this.

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


All controls in your master page should be inside a <form>...</form> tag, including your content placeholders.

This has nothing to do with a "contact page". This is fundamental to ASP.NET pages in general.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜