Web Server Control
Web Server Control
Controls are small building blocks of the graphical user interface, which include text boxes, buttons,
check boxes, list boxes, labels, and numerous other tools. Using these tools, the users can enter data,
make selections and indicate their preferences.
Controls are also used for structural jobs, like validation, data access, security, creating master pages,
and data manipulation.
ASP.NET uses five types of web controls, which are:
HTML controls
HTML Server controls
ASP.NET Server controls
ASP.NET Ajax Server controls
User controls and custom controls
ASP.NET server controls are the primary controls used in ASP.NET. These controls can be grouped
into the following categories:
Validation controls - These are used to validate user input and they work by running client-
side script.
Data source controls - These controls provides data binding to different data sources.
Data view controls - These are various lists and tables, which can bind to data from data
sources for displaying.
Personalization controls - These are used for personalization of a page according to the user
preferences, based on user information.
Login and security controls - These controls provide user authentication.
Master pages - These controls provide consistent layout and interface throughout the
application.
Navigation controls - These controls help in navigation. For example, menus, tree view etc.
Rich controls - These controls implement special features. For example, AdRotator,
FileUpload, and Calendar control.
In addition, visual studio has the following features, to help produce in error-free coding:
ASP.NET server controls with a visual aspect are derived from the WebControl class and inherit all
the properties, events, and methods of this class.
The WebControl class itself and some other server controls that are not visually rendered are derived
from the System.Web.UI.Control class. For example, PlaceHolder control or XML control.
ASP.Net server controls inherit all properties, events, and methods of the WebControl and
System.Web.UI.Control class.
The following table shows the inherited properties, common to all server controls:
Property Description
AccessKey Pressing this key with the Alt key moves focus to the control.
Attributes It is the collection of arbitrary attributes (for rendering only) that do not
correspond to properties on the control.
ChildControlCreated It indicates whether the server control's child controls have been
created.
Method Description
ApplyStyleSheetSkin Applies the style properties defined in the page style sheet to
the control.
ClearChildState Deletes the view-state and control-state information for all the
server control's child controls.
ClearChildViewState Deletes the view-state information for all the server control's
child controls.
CreateControlStyle Creates the style object that is used to implement all style
related properties.
Example
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace eventdemo {
public partial class treeviewdemo : System.Web.UI.Page {
if(childnodes != null) {
txtmessage.Text = " ";