简体   繁体   中英

asp.net controls that may appear outside of form tag with runat="server"

I am experimenting with asp.net controls and came across this article that states that All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. .

I tried to run a simple aspx page with no form and a table asp:table and it renders fine. I also tried the same with a label and it's fine too. With a button on the other hand, it returns an error page that claims that a button control must appear within a form tag with a runat="server" attribute, as expected.

What distincts controls that may appear outside a form tag from those which must appear within a form tag? I could not find anything on docs.microsoft

I suspect that the initial tests "render fine" but would have other bugs under various edge cases. For example, if any of those controls need to persist any state across page loads, they would likely fail to do so.

Basically, nothing distinguishes controls which work vs. don't work outside of the over-arching form. None of them are guaranteed to work outside of the form. Always put WebForms controls within the over-arching <form> that encloses each page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM