0% found this document useful (0 votes)
209 views

Web Server Control

ASP.NET uses server controls which are building blocks for creating user interfaces. There are different types of server controls including validation controls, data source controls, and login/security controls. Server controls inherit common properties from the WebControl class like ID, style, and events. Methods allow controls to add child controls, apply styles, and manage view state.

Uploaded by

Anantha Priya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views

Web Server Control

ASP.NET uses server controls which are building blocks for creating user interfaces. There are different types of server controls including validation controls, data source controls, and login/security controls. Server controls inherit common properties from the WebControl class like ID, style, and events. Methods allow controls to add child controls, apply styles, and manage view state.

Uploaded by

Anantha Priya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASP.

NET - Server Controls

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:

 Dragging and dropping of controls in design view


 IntelliSense feature that displays and auto-completes the properties
 The properties window to set the property values directly
Properties of the Server Controls

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.

BackColor Background color.

BindingContainer The control that contains this control's data binding.

BorderColor Border color.

BorderStyle Border style.

BorderWidth Border width.

CausesValidation Indicates if it causes validation.

ChildControlCreated It indicates whether the server control's child controls have been
created.

ClientID Control ID for HTML markup.


Methods of the Server Controls

The following table provides the methods of the server controls:

Method Description

AddAttributesToRender Adds HTML attributes and styles that need to be rendered to


the specified HtmlTextWriterTag.

AddedControl Called after a child control is added to the Controls collection


of the control object.

AddParsedSubObject Notifies the server control that an element, either XML or


HTML, was parsed, and adds the element to the server control's
control collection.

ApplyStyleSheetSkin Applies the style properties defined in the page style sheet to
the control.

ClearCachedClientID Infrastructure. Sets the cached ClientID value to null.

ClearChildControlState Deletes the control-state information for the server control's


child controls.

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.

CreateChildControls Used in creating child controls.

CreateControlCollection Creates a new ControlCollection object to hold the 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 {

protected void Page_Load(object sender, EventArgs e) {


txtmessage.Text = " ";
}

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) {

txtmessage.Text = " ";


lblmessage.Text = "Selected node changed to: " + TreeView1.SelectedNode.Text;
TreeNodeCollection childnodes = TreeView1.SelectedNode.ChildNodes;

if(childnodes != null) {
txtmessage.Text = " ";

foreach (TreeNode t in childnodes) {


txtmessage.Text += t.Value;
}
}
}
}
}

You might also like