Page 55 - DCAP312_WEB_TECHNOLOGIES_II
P. 55
Unit 3: Server Controls Basic
3.3 Web Server Controls Notes
ASP.NET pages are complete of code, mark-up tags, factual text, and server controls. Based on the
demand, the server reins generate the right mark-up language. The ASP.NET runtime combines
the output of all controls and serves the client a page to display in a browser. The programming
richness of ASP.NET springs from the wide library of server controls that covers the basic tasks
of HTML interaction for example, collecting text through input tags—as well as more advanced
functionalities such as calendaring, menus, tree views, and grid-based data display.
Key to ASP.NET control programming is the run at characteristic. If a tag in the .aspx basis is
declared without the run at quality, it is considered plain text and is output verbatim. Otherwise,
the contents of the tag are mapped to a server control and processed during the page life cycle.
We identified two main families of server control HTML server controls and Web server controls.
HTML controls map to HTML tags and are implemented through server-side classes whose
programming interface faithfully represents the standard set of attributes for the corresponding
HTML tag. Web controls, in turn, are a more abstract library of controls in which adherence
of the proposed API to HTML syntax is much less strict. As a result, Web and HTML controls
share a large common subset of functionalities and, in spite of a few exceptions; we could say
that Web controls, functionally speaking, are a superset of HTML controls. Web controls also
feature a richer development environment with a larger set of methods, properties and events,
and they participate more actively in the page life cycle.
As we will see in more detail in the following pages, a second and more thoughtful look at the
characteristics of the server controls in ASP.NET reveals the existence of more than just two
families of controls. In real world ASP.NET applications, we will end up using controls from at
least the following functional categories: HTML controls, core Web controls, validation controls,
data-bound controls, user controls, mobile controls, and custom controls. Validation controls are
a special subset of Web controls and deserve to be treated in a separate section.
Data-bound controls refer to data binding and therefore to the control’s capability of connecting
some of its properties to particular data sources. Hence, data-bound controls deserve a section of
their own because of the difference in how they are used. User controls are visual aggregates of
existing Web and HTML controls that appear as individual, encapsulated, programmable controls
to external callers. Mobile controls are used when creating Web applications that target mobile
devices. Custom controls refer to server controls we create entirely with code (not visually, as
with a user control) that derive from a base control class.
Web server controls are special ASP.NET tags understood by the server. Like HTML server
controls, Web server controls are also created on the server and they require a run at= “server”
attribute to work. However, Web server controls do not necessarily map to any existing HTML
elements and they may represent more complex elements.
The syntax for creating a Web server control is:
<asp:control_name id= “some_id” runat= “server” />
In the following example we declare a Button server control in an .aspx file. Then we create an
event handler for the Click event which changes the text on the button:
<script runat= “server”>
Sub submit(Source As Object, e As EventArgs)
button1.Text= “You clicked me!”
End Sub
</script>
<html>
LOVELY PROFESSIONAL UNIVERSITY 49