ASP (Web Server) Controls
The third type of control is the ASP
control
, also known as the ASP
server control or the web server
control
. In this book,
we will refer to it as an ASP control, since the syntax used to
implement it is of the form:
<asp:controlType
id="ControlID"
runat="server" />where the control tag always begins with asp:. ASP
controls offer a more consistent programming model than the analogous
HTML server control. For example, in HTML, the input tag
(<input>) is used for buttons, single-line
text fields, checkboxes, hidden fields, and passwords. For multiline
text fields, you must use the <textarea>
tag. With ASP controls, each different type of functionality
corresponds to a specific control. For example, all text is entered
using the TextBox control; the number of lines is specified using a
property. In fact, for ASP controls in general, all the attributes
correspond to properties of the control.
The ASP controls also include additional, rich controls, such as the Calendar and AdRotator.
Example 4-5 and Example 4-6 demonstrate the use of ASP controls in a web page analogous to the HTML server controls of Example 4-1 and Example 4-2. They show the use of the TextBox and Button ASP controls, rather than of the HTML controls.
Example 4-5. Code listing for csASPServerControls1.aspx
<%@ Page Language="C#" %>
<html>
<script runat="server">
void btnBookName_Click(Object Source, EventArgs E)
{
lblBookName.Text = txtBookName.Text; } </script> <body> <form runat="server"> ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access