Must be Placed Inside a Form Tag With runat=server
Asked Answered
S

5

14

I have been attempting this all morning with no results. I can't seem to figure out what I'm doing wrong. I have checked out the two links (among many other unhelpful links) and have yet to solve my issue. This is a WebUserControl...

Receiving the following error:

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

Already attempted the suggestions here, here and here and no results. Still received the exact same message. Some new suggestions would be greatly appreciated!

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Careers View Posting.ascx.cs" Inherits="ascxStagingApplication.Careers.Careers_View_Posting" %>
<asp:Panel ID="pnlResume" runat="server">
    <table ID="tblMain" runat="server">
        <tr>
            <td>
                <asp:Label ID="lblFirstName" runat="server" Text="* First Name"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblLastName" runat="server" Text="* Last Name"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblEmail" runat="server" Text="* Email"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </td>

        </tr>
        <tr>
            <td>
                <asp:Label ID="lblResume" runat="server" Text="* Resume"></asp:Label>
            </td>
            <td>
                <asp:FileUpload ID="fupResume" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnSubmit" runat="server" Text="Submit"/>
            </td>
        </tr>
    </table>
</asp:Panel>

The user control is currently being placed onto a dummy webpage for testing. Here is the 'dummy' page code.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>

<%@ Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
Suomi answered 4/2, 2014 at 13:30 Comment(2)
Where are you using this UserControl?Malta
@TimSchmelter Added the page code above. Sorry about that!Suomi
B
18

In ASPNet webforms - everything needs to run within a form tag.

All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts:

<form runat="server">

...HTML + server controls

</form>

In your dummy page try the following to allow the server controls to run.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>

<%@ Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<form runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
</form>

Also - check that your ~/Site.Master file contains the <form runat="server"> if not -a s it would be fairly typical for that to be the place to have your all enclosing form tag.

You could read more here: http://www.w3schools.com/aspnet/aspnet_forms.asp

Bilestone answered 4/2, 2014 at 13:44 Comment(1)
MS offical docs also say this -learn.microsoft.com/en-us/aspnet/web-forms/overview/…Dicot
U
5

If you put right of runat="server" but still error, please try this code.

 public override void VerifyRenderingInServerForm(Control control)
    {
         /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
       server control at run time. */
    }

cr. from Rohit Rao

sorry for my bad skill English.

Ulu answered 29/8, 2018 at 2:28 Comment(0)
D
1

All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.

All the Asp.net controls are server controls,so these should be placed within form tag with runat="server" attribute, like this

<form runat="server">

place server controls here...

</form>
Driskill answered 18/1, 2016 at 17:47 Comment(0)
G
-4
>Button bt = new Button();
>bt.ID = "dd";
>bt.Text = "Click Me";
>this.Form.Controls.Add(bt);
Goodfellowship answered 1/6, 2016 at 10:3 Comment(1)
While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations!Fukuoka
C
-5

you can add

<form runnat="server">
 // add content placeholder
</form>
Chirk answered 4/5, 2015 at 3:49 Comment(1)
should be runat not runnat.Clevie

© 2022 - 2024 — McMap. All rights reserved.