News & UpdatesProgrammingWeb programming Store My Projects
Links
Affiliates

ASP.NET Tutorial – 04 – Form Control

Form element and Form control

The <form> element used in ASP.NET is actually called the form control, because of the runat=”server” attribute. What makes this control special is that all other ASP.NET controls must be located inside of it.

<form id="myForm" runat="server"> </form><!-- form control -->
<form action="handler.aspx"> </form>     <!-- form element -->

If, for example, a Button control is placed outside of the form, the server won’t allow it. It will display an error message instead of the expected web page when the web application is run.

<asp:Button ID="myButton" runat="server" Text="Button"/>

Same thing if more than one form control is added to a single page.

<form id="myForm1" runat="server"> </form>
<form id="myForm2" runat="server"> </form>

Elements and Controls

The difference between an HTML element and a ASP.NET control is that controls are objects, while elements are simply HTML markup. Although many of the controls directly represent HTML elements, they’re not always translated so straight forward. For example, while the <form> element requires the action attribute, this attribute is not specified for the form control. This is because ASP.NET will automatically fill out this attribute when it translates the control into its HTML representation. The form control will also translate into a hidden field called viewstate. This field is needed to maintain the state of the page so that a submitted form can reappear with all of its form values intact.

Recommended additional reading:
Sams - Teach Yourself ASP.NET 3.5 in 24 Hours