Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When a form with a run at server is added there will be two forms with runat server and another error occurs. Can some one give me an idea. Thankx in advance.

The details of the error are as follows.

Control 'ctl00_TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'ctl00_TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Control 'ctl00_TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +2052287
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +49
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

Version Information: Microsoft .NET Framework Version:2.0.50727.1873; ASP.NET Version:2.0.50727.1433

like image 334
Hiru Avatar asked Mar 22 '10 06:03

Hiru


3 Answers

The error states the problem

Correct

<form id="frm" runat="server">
    <asp:TextBox id="txt" runat="server" />
</form>

Incorrect

<asp:TextBox id="txt" runat="server" />
<form id="frm" runat="server">
</form>
like image 152
Dustin Laine Avatar answered Oct 05 '22 20:10

Dustin Laine


Seeing the tag "master-pages" included in the question, this error may pop up when you are trying to dynamically add text boxes (or for that matter, any control) in a content page which uses a master page.

Only the master page contains a form with runat="server" set. The content pages only have content place holders.

To dynamically add controls to a content page, include a panel in your desired contentplaceholder in your content page and then add controls to it in your code. For example,

In your aspx file for the content page, add a panel like

<asp:Panel ID="Panel1" runat="server">
</asp:Panel>   

Then, in your code behind,

        Dim txtbox As New textbox()
        Panel1.Controls.Add(txtbox)
like image 40
user720694 Avatar answered Oct 05 '22 21:10

user720694


Error happens because you placed your control with runat="server" outside the form tag (with runat="server" too). ASP.NET requires to have all server controls inside one form with runat="server" attribute.

like image 20
Andrew Bezzub Avatar answered Oct 05 '22 21:10

Andrew Bezzub