all the code inside the .aspx file instead), the Page class is still usedwe just
dont see it.
We can use a range of user interface elements inside the formincluding typical,
static HTML codebut we can also use elements whose values or properties can
be generated or manipulated on the server either when the page first loads, or
when the form is submitted. These elementswhich, in ASP.NET parlance, are
called controlsallow us to reuse common functionality, such as the page header,
a calendar, a shopping cart summary, or a Todays Quote box, for example,
across multiple web forms. There are several types of controls in ASP.NET:
HTML server controls
web server controls
web user controls
master pages
There are significant technical differences between these types of controls, but
what makes them similar is the ease with which we can integrate and reuse them
in our web sites. Lets take a look at them one by one.
HTML Server Controls
HTML server controls are outwardly identical to plain old HTML tags, but include
a runat="server" attribute. This gives the ASP.NET runtime control over the
HTML server controls, allowing us to access them programatically. For example,
if we have an <a> tag in a page and we want to be able to change the address to
which it links dynamically, using VB or C# code, we use the runat="server"
attribute.
A server-side HTML server control exists for each of HTMLs most common
elements. Creating HTML server controls is easy: we simply stick a runat="serv-
er" attribute on the end of a normal HTML tag to create the HTML control
version of that tag. The complete list of current HTML control classes and their
associated tags is given in Table 4.1.
95
HTML Server Controls
Table 4.1. HTML control classes
Associated TagsClass
<a runat="server">HtmlAnchor
<button runat="server">HtmlButton
<form runat="server">HtmlForm
<img runat="server">HtmlImage
<input type="submit" runat="server">HtmlInputButton
<input type="reset" runat="server">
<input type="button" runat="server">
<input type="checkbox" runat="server">HtmlInputCheckBox
<input type="file" runat="server">HtmlInputFile
<input type="hidden" runat="server">HtmlInputHidden
<input type="image" runat="server">HtmlInputImage
<input type="radio" runat="server">HtmlInputRadioButton
<input type="text" runat="server">HtmlInputText
<input type="password" runat="server">
<select runat="server">HtmlSelect
<table runat="server">HtmlTable
<tr runat="server">HtmlTableRow
<td runat="server">HtmlTableCell
<th runat="server">
<textarea runat="server">HtmlTextArea
<span runat="server">HtmlGenericControl
<div runat="server">
All other HTML tags
For more details on these classes, see Appendix A.
All the HTML server control classes are contained within the System.Web.UI.Htm-
lControls namespace. As theyre processed on the server side by the ASP.NET
runtime, we can access their properties through code elsewhere in the page. If
youre familiar with JavaScript, HTML, and CSS, then youll know that manipu-
lating text within HTML tags, or even manipulating inline styles within an HTML
96
Chapter 4: Constructing ASP.NET Web Pages

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.