tags:

views:

82

answers:

5

Simply,

When creating a new aspx page in Visual studio, it automatically adds tags like these:

<form id="form1" runat="server">

Are these form tags required to wrap the entire HTML output of the page? e.g.:

<body>
<form id="form1" runat="server">
HTML GOES HERE
</form>
</body>

Or can they just be placed where you require an actual form? Thanks

+6  A: 

The form tags just need to be placed around any ASP.NET server controls. If they only exist within the actual form or you're not using any then it's ok to do so.

ctrlalt3nd
+3  A: 

The simple/simplistic anwser is - if you want to use .NET server controls then they'll need to be within the <form runat="server"> block.

LukeH
Always liked simplistic answers! ;-)
Cerebrus
+2  A: 

Providing everything that you want posted back to the server is within the form tags (including viewstate, hidden fields, normal html form controls) then you can put html above and below them. But for beginners I'd suggest you put all your html between them to keep things simple.

cjuk
+1  A: 

Also, it must be the only form on the page. If you do need to use an individual form, use the PostbackUrl of the Button.

Lucas Jones
+1  A: 

Essentially yes, but corner-case no. ASP.NET appropriates the form element to handle things like viewstate, session, client side binding. It's also why you can't have two forms on a page.

annakata