asp.net - Control [...] of type [...] must be placed inside a form tag with runat=server - but already is -


asp.net says asp:button needs inside <form runat="server". inside form. why still wrong?


default.aspx:

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %>  <!doctype html> <html>     <head>         <title>test case</title>     </head>     <body>         <asp:placeholder runat="server" id="ph"/>         <form runat="server">             <asp:button runat="server" text="foobar"/>         </form>     </body> </html> 

default.aspx.cs:

using system; using system.web.ui.webcontrols;  public partial class _default : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {         ph.controls.add(new button());     } } 

error message:

control 'ctl02' of type 'button' must placed inside form tag runat=server.

stack trace:

[httpexception (0x80004005): control 'ctl02' of type 'button' must placed inside form tag runat=server.]

system.web.ui.page.verifyrenderinginserverform(control control) +9745742 system.web.ui.webcontrols.button.addattributestorender(htmltextwriter writer) +62 system.web.ui.webcontrols.webcontrol.renderbegintag(htmltextwriter writer) +20 system.web.ui.webcontrols.webcontrol.render(htmltextwriter writer) +20 system.web.ui.control.rendercontrolinternal(htmltextwriter writer, controladapter adapter) +66 system.web.ui.control.rendercontrol(htmltextwriter writer, controladapter adapter) +100 system.web.ui.control.rendercontrol(htmltextwriter writer) +25 system.web.ui.control.renderchildreninternal(htmltextwriter writer, icollection children) +128 system.web.ui.control.renderchildren(htmltextwriter writer) +13 system.web.ui.control.render(htmltextwriter writer) +12 system.web.ui.control.rendercontrolinternal(htmltextwriter writer, controladapter adapter) +66 system.web.ui.control.rendercontrol(htmltextwriter writer, controladapter adapter) +100 system.web.ui.control.rendercontrol(htmltextwriter writer) +25 system.web.ui.control.renderchildreninternal(htmltextwriter writer, icollection children) +128 system.web.ui.control.renderchildren(htmltextwriter writer) +13 system.web.ui.page.render(htmltextwriter writer) +29 system.web.ui.control.rendercontrolinternal(htmltextwriter writer, controladapter adapter) +66 system.web.ui.control.rendercontrol(htmltextwriter writer, controladapter adapter) +100 system.web.ui.control.rendercontrol(htmltextwriter writer) +25 system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +5827

it looks (based on posted code) error resulting adding button in page_load method. adding controls collection of placeholder ph, not inside form tag.

try placing placeholder tag inside form tag:

<body>   <form id="frm1" runat="server">     <asp:placeholder runat="server" id="ph" />     <asp:button runat="server" text="foobar" /> </body> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -