GalSuchetzky
GalSuchetzky

Reputation: 795

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

Upvotes: 0

Views: 373

Answers (1)

David
David

Reputation: 218798

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.

Upvotes: 0

Related Questions