HTML and CSS Reference
In-Depth Information
The <form> Element in ASP.NET Web Forms
A typical ASP.NET web form consists of a
<form>
tag marked with the
runat
server. Additionally, it hosts one
or more server controls such as text boxes, lists, and grids. Finally, it provides a mechanism to submit a
form to the server for further processing. Listing 5-1 shows a simple web form that illustrates how these
elements look in source view.
Listing 5-1.
A Server-Side
<form>
Element in a Web Forms Application
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Enter your Name : " ></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</form>
The
<form>
tag in Listing 5-1 has two attributes:
id
and
runat
. If you wish to process an HTML form on
the server, it must be marked with
runat
. The
runat
attribute has only one possible value:
server
. In the
<form>
are a
Label
server control, a
TextBox
server control, and a
Button
server control. If you run this web
form in a browser, you get the display shown in Figure 5-1.
Figure 5-1.
A simple web form displayed in a browser
If you view the HTML source of the resulting page shown by the browser, it's as shown in Listing 5-2.
Listing 5-2.
HTML Source of a Web Form
<form method="post" action="WebForm1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="kv16mNsClgHGNtkmN…" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="jIRq9NWtI20O4IJRVRDv7…" />
</div>
<span id="Label1" >Enter your Name : </span>
<br />
<input name="TextBox1" type="text" id="TextBox1" />