Types of asp.
net webserver controls
Web server controls include traditional form controls such as buttons and text boxes as well
as complex controls such as tables. They also include controls that provide commonly used
form functionality such as displaying data in a grid, choosing dates, displaying menus, and so
on.
Advantages of Web Server Controls
Web Server Controls provide the following advantages:
The controls map (mostly, but not always) to their corresponding HTML elements.
This makes it easier for developers to automatically generate a user interface.
Since the controls are pre-packed with interactive HTML elements, the process of
creating web forms becomes less prone to errors and is more consistent.
All Web Server Controls derive from Web.UI.WebControls.WebControl base class.
Thus, they inherit all the basic Web Control features and methods.
Types of webserver controls are Basic web controls, validation controls, List controls,
Rich controls.
1. Basic Web Controls
Basic Web Controls are the ones similar to HTML Server Controls. They provide the same
functionality with additional methods, events, and properties, which the developers can
leverage to write their own code.
Examples of Basic Web ASP.NET Server Controls: Button, Checkbox, HyperLink, Image,
ImageButton, Label, LinkButton Web Server Control
Button Control
<asp:Button id="submitBtn" text="Submit" OnClick="submitForm"
runat="server"/> HyperLink Control
<asp:HyperLink id="link1" NavigateURL="www.google.com" Text="Go to Google"
Target="window" runat="server"/> Label Control
<asp:Label id="headerLabel" Text="Welcome to EduCBA" runat="server"/>
2. Validation Controls
Validation Controls in ASP.Net are used to validate the inputs by the user. These controls can
perform pre-defined as well as custom validations. Depending on the browser compatibility,
the validations are performed either on the client-side or server-side. This decision is
automatically performed by the controls. Client-side validation is performed in the client
browser i.e. before a postback call is triggered to the server. Server-side validation is
performed after the form has been submitted to the server.
Validation Controls are not standalone controls. Rather they are associated with other
controls in the web page or web form. More than one validation control can be associated
with each control to be validated. The validation is performed when the user submits the page
or the form.
Examples of Validation Controls: RequiredFieldValidator Control, RangeValidator
Control, CompareValidator Control, RegularExpressionValidator Control,
CustomValidator Control
Required Field Validator
<asp:TextBox id="tb_name" runat="server"/><asp:RequiredFieldValidator id="RFV_tb"
ControlToValidate="tb_name" ErrorMessage="This field is required!"
runat="server"/> Compare Validator
<asp:TextBox id="tb_pwd" TextMode=”Password” runat="server"/><asp:TextBox
id="tb_re_pwd" TextMode=”Password” runat="server"/><asp:CompareValidator
id="CV_pwd" ControlToValidate="tb_re_pwd" ControlToCompare="tb_pwd"
Type=”String” runat="server"/>
3. List Controls
List Controls are special controls that generate pre-formatted list layouts. These controls bind
to the collections and display the collected data in rows of a customized or templated format.
For this reason, List Controls only bind to collections that implement
IEnumerable, ICollection, or IListSource interfaces. The data to be bound to the List Controls
are defined by DataSource and DataMember properties.
<script runat="server">Public void Page_Load(){ count_rptr.DataSource = new String[]
{"Uno","Due","Tre"}; count_rptr.DataBind();}</script><html> <body>
<asp:repeater id=count_rptr runat="server"> <itemtemplate><%#
Container.DataItem %><br></itemtemplate> </asp:repeater> </body></html>
The above code will output Uno, Due, Tre, as a list spanning three lines.
List controls are ListBox Web Server Control, CheckBoxList Web Server Control,
RadioButtonList Web Server Control, DataList Web Server Control, DataGrid Web
Server Control, DropDownList Web Server Control
4. Rich Controls
Rich Web Controls are complex HTML controls that are intended to provide a rich user
experience. These are task-specific controls. Unlike the simple web form native HTML
controls, the Rich Controls perform a complex task. This can be a woven suite of several
simple HTML controls or a more enhanced layout. Examples of Rich Controls are Calendar
Control, XML Control, AdRotator Control, etc.
The Calendar Control is responsible for showing a date-picker element that the user can very
conveniently use to select a date.
The XML Control generates an XML layout for the given data. XML layout is a tag-
controlled layout in which data is enclosed within tags. These tags serve as the keys while the
data within serve as the values.
The AdRotator control is responsible for displaying an advertisement banner on the web
page.