All the controls have a unique functionality associated with it. They can be used for accessing web pages, validating data, develop master pages, navigating data, etc. Depending on the functionality and use, the ASP.NET controls are differentiated into five different types as listed below. HTML controls HTML Server controls ASP.NET Server controls Ajax server controls Custom and user controls The server controls are divided into different categories as listed below. Data Source controls: The controls are used for binding data to various sources. Data View controls: The data controls like list and tables are used for displaying data by binding to the data source. Validation controls: The user input is validated using the validation controls. Master pages: A unique interface is provided for all the pages in the web application. Personalization controls: The page is personalized as per the user information. Rich controls: The controls provide rich user interface and functionality. The controls like Calendar, AdRotator, FileUpload, Multi View are used. Login and security controls: The user authentication is provided using these controls. Navigation controls: User can navigate through the data using the navigation controls. The menu, tree view, etc are used. The general syntax for adding a server control is: Code: <asp:controlType ID="ControlID" runat="server" Property1=value1 [Property2=value2]> Properties of server controls The server controls are derived from the Web Control class. All the events, methods and properties are inherited from the class. They are derived from System.Web.UI.Control class. Some of the properties of the web server controls are as listed below. Attributes: Collection of arbitrary attributes that are not related to the control properties. AccessKey: The key along with the Alt key provides focus to the control. BorderColor: The border color of the control is changed BackColor: The background color of the control is modified BorderStyle: The border style of the control can be changed BindingContainer: The data binding of the control is present in the container. ClientID: The control ID for the HTML markup is added ChildControlCreated: It checks for the creation of child control for the corresponding server control Context: The HTTPContext object is used with the server control Controls: Collection of controls inside the control Cssclass: The CSS class is present DesignMode: It states whether the control is used in the design view DataKeysContainer: The reference of the naming container implementing the IDataKeysControl is used. DataItemContainer: The reference of the naming container implementing the IDataItemContainer is used. EnableViewState: Checks whether the view state of the control is enabled Events: The list of event handler delegates for the control HasAttributes: Checks whether the control has attributes ID: Used for identifying the control IsTrackingViewState: It checks whether server control is saving the changes to the view state. Site: It the container that hosts the control when rendered on the design view. SkinID: It accesses or assigns the skin to be applied to the control TagName: It retrieves the name of the control tag ViewState: The directory of the state information is saved. The information about the view state of the server control is restored Width: The width of the control is accessed or modified. UniqueID: It is the unique identifier of the control Methods of server controls The list of methods provided by the server controls are: AddedControl: It is called when the child control is added to the Collections object. AddAttributesToRender: The HTML attributes and styles are added and rendered to the HtmlTextWriter Tag ApplyStyleSheetSkin: The style properties are defined in the style sheet of the control. ClearCachedClientID: The cached control client ID value is set to null. ClearChildControlState: The control state data for all the server controls is deleted. CreateChildControls: The child controls are created. CreateControlCollection: A new ControlCollection object contains the child controls CreateControlStyle: The style object used for implementing the style properties is created. DataBind: It binds the data source to the server control and child controls Dispose: The server control performs the clean up before the memory is released Equals(Object): It checks whether the object is equal to the current object Focus: It acquires the focus to the control HasControls: Checks whether the control has child controls. LoadViewState: The view state information is restored MapPathSecure: The physical and virtual path, either absolute or relative is mapped. MergeStyle: The non blank elements are copied to the web control. The existing elements are not overwritten. OnInit: The Init event is raised OnUnload: The Unload event is raised Render: The control is rendered to the specific HTML writer. RenderContents: The contents of the control are rendered to the specific writer SaveControlState: The server control state is changed. SetDesignModeState: The design time data of the control is set TrackViewState: The modifications to the view state are tracked by the user. They are saved in the view state property of the object. Example to demonstrate the server controls Let’s consider the example to demonstrate the Tree View control in ASP.NET. Following steps are performed for creating the server controls in ASP.NET application. Open Visual Studio application in the system. Create an ASP.NET web application. Add a tree view control on the web page as shown below: Select the Edit Nodes option from the list. Edit the nodes using the Tree View node editor. Add the following code in the source view window of the application. Code: <form id="form1" runat="server"> <asp:TreeView ID="TreeView1" runat="server" onselectednodechanged = "TreeView1_SelectedNodeChanged"> <Nodes> <asp:TreeNode Text="School Information" Value="School Information"> </asp:TreeNode> <asp:TreeNode Text="Home" Value="Home"> <asp:TreeNode Text="Overview" Value="Overview"> </asp:TreeNode> <asp:TreeNode Text="Academics" Value="Academics"> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Management" Value="Management"> <asp:TreeNode Text="Staff" Value="Staff"> </asp:TreeNode> <asp:TreeNode Text="Ajay Sharma" Value="Ajay Sharma" /> <asp:TreeNode Text="Yogesh Singh" Value="Yogesh Singh" /> <asp:TreeNode Text="Pravin Patil" Value="Pravin Patil" /> </asp:TreeNode> </asp:TreeNode> </Nodes> </asp:TreeView> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"> </asp:TextBox> </div> </form> In the code behind file, add the following code. Code: using System; using System.Web; using System.Web.UI; using System.Web.UI.controls; using System.Linq; public partial class _Default: System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = " "; } protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { TextBox1.Text=" "; Label1.Text = "The selected node is:"+TreeView1.SelectedNode.Text; TreeNodeCollection nodes = TreeView1.SelectedNode.ChildNodes; if ( nodes ! = null) { TextBox1.Text = " "; foreach( TreeNode t in nodes ) { TextBox1.Text += t.value; } } } } Compile and execute the code and the following output is generated.