asp.net_server_controls
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.
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.
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:
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.
ChildControlCreated It indicates whether the server control's child controls have been
created.
DisabledCssClass Gets or sets the CSS class to apply to the rendered HTML element
when the control is disabled.
Font Font.
HasChildViewState Indicates whether the current server control's child controls have
any saved view-state settings.
IsTrackingViewState It indicates whether the server control is saving changes to its view
state.
RenderingCompatibility It specifies the ASP.NET version that the rendered HTML will be
compatible with.
Site The container that hosts the current control when rendered on a
design surface.
TabIndex Gets or sets the tab index of the Web server control.
TemplateSourceDirectory Gets the virtual directory of the page or control containing this
control.
ToolTip Gets or sets the text displayed when the mouse pointer hovers
over the web server control.
ViewState Gets a dictionary of state information that saves and restores the
view state of a server control across multiple requests for the
same page.
Method Description
AddAttributesToRender Adds HTML attributes and styles that need to be rendered to the
specified HtmlTextWriterTag.
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.
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.
CreateControlStyle Creates the style object that is used to implement all style related
properties.
DataBind Binds a data source to the server control and all its child controls.
DataBindBoolean Binds a data source to the server control and all its child controls
with an option to raise the DataBinding event.
FindControlString Searches the current naming container for a server control with
the specified id parameter.
FindControlString, Int32 Searches the current naming container for a server control with
the specified id and an integer.
HasEvents Indicates whether events are registered for the control or any child
controls.
MapPathSecure Retrieves the physical path that a virtual path, either absolute or
relative, maps to.
MergeStyle Copies any nonblank elements of the specified style to the web
control, but does not overwrite any existing style elements of the
control.
OnBubbleEvent Determines whether the event for the server control is passed up
the page's UI server control hierarchy.
RemovedControl Called after a child control is removed from the controls collection
of the control object.
RenderBeginTag Renders the HTML opening tag of the control to the specified
writer.
RenderEndTag Renders the HTML closing tag of the control into the specified
writer.
ResolveAdapter Gets the control adapter responsible for rendering the specified
control.
SaveControlState Saves any server control state changes that have occurred since
the time the page was posted back to the server.
SaveViewState Saves any state that was modified after the TrackViewState
method was invoked.
Example
Let us look at a particular server control - a tree view control. A Tree view control comes under
navigation controls. Other Navigation controls are: Menu control and SiteMapPath control.
Add a tree view control on the page. Select Edit Nodes... from the tasks. Edit each of the nodes
using the Tree view node editor as shown:
Once you have created the nodes, it looks like the following in design view:
The AutoFormat... task allows you to format the tree view as shown:
Add a label control and a text box control on the page and name them lblmessage and txtmessage
respectively.
Write a few lines of code to ensure that when a particular node is selected, the label control
displays the node text and the text box displays all child nodes under it, if any. The code behind the
file should look like this:
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 = " ";
Execute the page to see the effects. You will be able to expand and collapse the nodes.
Loading [MathJax]/jax/output/HTML-CSS/jax.js