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

只愿长相守 提交于 2019-12-10 13:45:34

问题


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


回答1:


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>



回答2:


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)



回答3:


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.




回答4:


With standard ASP.Net, you can only have one form. Thats a limitation of ASP.Net. If youre going to be doing stuff that requires 2 or more <FORM> tags, you'll need MVC or something along the lines of.




回答5:


I ran into this too. What I did, was just added a PageWrapper , and all the site's code went inside that. For example:

<body>
 <div ID="PageWrapper">
    <form ID="form1" runat="server">
        <div ID="Header">...</div>
        <div ID="MainContent">...</div>
         ...
    </form>
 </div>
</body>

Something like that. Hope this helps.




回答6:


You did not say where this control is on your form.

If this error is a result of another control being inside a GridView control like I had, then this may help you, too:

Control xxx of type 'LinkButton' must be placed inside a form tag with runat=server




回答7:


Error is Control 'txtTo' of type 'TextBox' which must be placed inside a form tag with runat=server.

ERROR is This Code.

      <tr>
          <td class="style1">
                <strong>To </strong>
            </td>
            <td class="style2">
                <strong>: </strong>
            </td>
            <td class="style6">
                &nbsp;
                <asp:TextBox ID="txtTo" runat="server" Width="475px"></asp:TextBox>
            </td>
            <td></td>
        </tr>


来源:https://stackoverflow.com/questions/2490340/control-ctl00-textbox1-of-type-textbox-must-be-placed-inside-a-form-tag-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!