Intrinsic Controls
In the example we looked at earlier in this chapter, we saw how ASP+ provides
a series of Intrinsic Controls
that are intelligent. In other words, they can be executed on the server to
create output that includes event handling and the maintenance of state
(the values the controls display). In Chapters 2, 3, and 4, we look at how we
can use these controls in more detail, and explore their various capabilities.
However, to overview the aims of the new ASP+ Intrinsic Controls, we can say
that they serve three main purposes:
- They allow the developer to
interact with the control on the server when the page is being created, in
particular by setting the values of properties or reacting to events that
are raised on the client.
- They automatically create the
appropriate HTML to preserve their current state, so that they display the
correct values as selected by the user when the page is reloaded – without
requiring the developer to write code to do this.
- They make development simpler
and faster, and promote reusability and better page design and structure by
encapsulating the repetitive code required for these tasks within the control.
The basic intrinsic controls are used by simply inserting the equivalent HTML
into the page, just as you would in earlier versions of ASP, but adding the
runat="server" attribute. The elements that are
implemented as specific objects in the preview version of ASP+ are:
|
<table>
|
<tr>
|
<th>
|
<td>
|
|
<form>
|
<input>
|
<select>
|
<textarea>
|
|
<button>
|
<a>
|
<img>
|
|
As in HTML, the <input> server control depends on the value of the type attribute. The output that the control creates is, of course, different
for each value.
All other HTML elements in an ASP+ page that are marked with the runat="server"
attribute are handled by a single generic HTML server control. It creates output
based simply on the element itself and any attributes you provide or set server-side
when the page is being created.
There is also a set of new ASP+ controls that can be defined within the page,
and which are prefixed with the namespace 'asp'.
These controls expose properties that correspond to the standard attributes
that are available for the equivalent HTML element. As with all server controls,
you can set these properties during the server-side Load
events of the page, or add them as attributes in the usual way, but using the
special property names. When rendered to the client, the properties are converted
into the equivalent HTML syntax.
For example, to create an instance of a ListBox
control, we can use:
<asp:ListBox rows="3" runat="server">
<asp:ListItem>Windows 98</asp:ListItem>
<asp:ListItem>Windows NT4</asp:ListItem>
<asp:ListItem>Windows 2000</asp:ListItem>
</asp:ListBox>
At runtime (in the preview version) the ASP+ code above creates the following
HTML, and sends it to the client:
<SELECT name="ListBox0" size="3">
<OPTION value="Windows 98">Windows 98</OPTION>
<OPTION value="Windows NT4">Windows NT4</OPTION>
<OPTION value="Windows 2000">Windows 2000</OPTION>
</SELECT>
A summary of the 'asp'-prefixed intrinsic
controls looks like this:
|
ASP+ Intrinsic Control
|
HTML Output Element
|
|
<asp:Button>
|
<input type="submit">
|
|
<asp:LinkButton>
|
<a href="jscript:__doPostBack(...)">...<a>
|
|
<asp:ImageButton>
|
<input type="image">
|
|
<asp:HyperLink>
|
<a href="...">...</a>
|
|
<asp:TextBox>
|
<input type="text" value="...">
|
|
<asp:CheckBox>
|
<input type="checkbox">
|
|
<asp:RadioButton>
|
<input type="radio">
|
|
<asp:DropDownList>
|
<select>...</select>
|
|
<asp:ListBox>
|
<select size="...">...</select>
|
|
<asp:Image>
|
<img src="...">
|
|
<asp:Label>
|
<span>...</span>
|
|
<asp:Panel>
|
<div>...</div>
|
|
<asp:Table>
|
<table>...</table>
|
|
<asp:TableRow>
|
<tr>...</tr>
|
|
<asp:TableCell>
|
<td>...</td>
|
These controls provide more standardized property sets than the HTML controls,
and make it easier to implement tools that can be used for designing and building
ASP+ pages and applications.