简体   繁体   English

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

[英]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. 'TextBox' 类型的控件 'ctl00_TextBox1' 必须放置在带有 runat=server 的表单标签内。 Description: An unhandled exception occurred during the execution of the current web request.说明:在执行当前 Web 请求期间发生未处理的异常。 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.异常详细信息:System.Web.HttpException:“TextBox”类型的控件“ctl00_TextBox1”必须放置在具有 runat=server 的表单标记内。

Source Error:源错误:

An unhandled exception was generated during the execution of the current web request.执行当前 Web 请求期间生成了未处理的异常。 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.] [HttpException (0x80004005): 'TextBox' 类型的控件 'ctl00_TextBox1' 必须放置在带有 runat=server 的表单标签内。]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +2052287 System.Web.UI.Page.VerifyRenderingInServerForm(控件控件) +2052287
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +49 System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +49
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17 System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17
System.Web.UI.WebControls.TextBox.Render(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.RenderControlInternal(HtmlTextWriter writer, ControlAdapter 适配器) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter 适配器) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Control.Render(HtmlTextWriter writer) +7 System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter 适配器) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter 适配器) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26 System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter 适配器) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter 适配器) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

Version Information: Microsoft .NET Framework Version:2.0.50727.1873;版本信息:Microsoft .NET Framework 版本:2.0.50727.1873; ASP.NET Version:2.0.50727.1433 ASP.NET 版本:2.0.50727.1433

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>

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. 看到问题中包含的标记“master-pages”,当您尝试在使用母版页的内容页面中动态添加文本框(或者就此而言,任何控件)时,可能会弹出此错误。

Only the master page contains a form with runat="server" set. 只有母版页包含设置了runat =“server”的表单。 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. 要动态地将控件添加到内容页面,请在内容页面中的所需contentplaceholder中包含一个面板,然后在代码中向其添加控件。 For example, 例如,

In your aspx file for the content page, add a panel like 在内容页面的aspx文件中,添加一个面板

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

Then, in your code behind, 然后,在你的代码背后,

        Dim txtbox As New textbox()
        Panel1.Controls.Add(txtbox)

Error happens because you placed your control with runat="server" outside the form tag (with runat="server" too). 发生错误是因为您将控件与runat =“server”放在表单标记之外(runat =“server”也是如此)。 ASP.NET requires to have all server controls inside one form with runat="server" attribute. ASP.NET要求使用runat =“server”属性在一个表单中包含所有服务器控件。

I ran into this too. 我也碰到了这个。 What I did, was just added a PageWrapper , and all the site's code went inside that. 我做了什么,只是添加了一个PageWrapper,所有网站的代码都在里面。 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. 希望这可以帮助。

With standard ASP.Net, you can only have one form. 使用标准ASP.Net,您只能拥有一个表单。 Thats a limitation of ASP.Net. 这是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. 如果您要做的事情需要2个或更多<FORM>标签,那么您将需要MVC或类似的东西。

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: 如果这个错误是由于我有一个GridView控件内的另一个控件的结果,那么这也可以帮助你:

Control xxx of type 'LinkButton' must be placed inside a form tag with runat=server 必须将带有'LinkBut​​ton'类型的控件xxx放在带有runat = server的表单标签内

Error is Control 'txtTo' of type 'TextBox' which must be placed inside a form tag with runat=server. 错误是'TextBox'类型的控件'txtTo',它必须放在带有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>

控件和表单标签都必须有runat="server"

暂无
暂无

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

相关问题 类型为&#39;TextBox&#39;的控件&#39;ctl00_txtDebug&#39;必须放置在带有runat = server的表单标记中 - Control 'ctl00_txtDebug' of type 'TextBox' must be placed inside a form tag with runat=server 类型为&#39;TextBox&#39;的控件&#39;ctl07&#39;必须放置在带有runat = server的表单标记中。 - Control 'ctl07' of type 'TextBox' must be placed inside a form tag with runat=server. 类型为&#39;TextBox&#39;的控件&#39;0&#39;必须放置在带有runat = server的表单标记中 - Control '0' of type 'TextBox' must be placed inside a form tag with runat=server 类型为“ RadioButton”的控件“ ctl00”必须置于带有runat = server的表单标记中 - Control 'ctl00' of type 'RadioButton' must be placed inside a form tag with runat=server 类型为“ DataControlLinkBut​​ton”的控件“ DataLoading1_gdvDataGroups_ctl01_ctl00”必须置于带有runat = server的表单标记中 - Control 'DataLoading1_gdvDataGroups_ctl01_ctl00' of type 'DataControlLinkButton' must be placed inside a form tag with runat=server &#39;TextBox&#39; 类型的控件 &#39;txtUserName&#39; 必须放置在带有 runat=server 的表单标签中 - Control 'txtUserName' of type 'TextBox' must be placed inside a form tag with runat=server 类型为&#39;TextBox&#39;的控件&#39;MainContent_forenameTxt&#39;必须放置在带有runat = server的表单标签中 - Control 'MainContent_forenameTxt' of type 'TextBox' must be placed inside a form tag with runat=server “TextBox”类型的控件“windowMasterSearchBox”必须放置在带有 runat=server 的表单标记中 - Control 'windowMasterSearchBox' of type 'TextBox' must be placed inside a form tag with runat=server 'Button' 类型的控件 'ctl02' 必须放置在带有 runat=server 的表单标签内 - Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server 类型[…]的控件[…]必须放置在带有runat = server的表单标记中-但已经是 - Control […] of type […] must be placed inside a form tag with runat=server - but already is
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM