Friday, December 7, 2007

ASP.NET Web Form Controls

The basic concept of using server controls allows the change to a more structured event-driven-programming model. This provides a cleaner programming environment that is easier to work in and debug when things go wrong.

  • The ASP.NET Web Form controls in general.

  • The basic Web Form input and navigation server controls.

  • The Web Form server controls used for building lists.

  • The 'rich' Web Form controls that provide complex compound interface elements

The WebControl Base Class

Like the HTML controls, most Web Form controls inherit their members (properties, method, and events) from a base class. In this case, it is WebControl, defined within the System.Web.UI.WebControls namespace. This class provides a wide range of members, many of which are only really useful if you are building your own controls that inherit from WebControl. The public members used most often are shown in the following table:

Member

Description

Attributes property

Returns a collection of all the attribute name/value pairs within the .aspx file for this control. Can be used to read and set non-standard attributes (custom attributes that are not actually part of HTML) or to access attributes where the control does not provide a specific property for that purpose.

AccessKey property

Sets or returns the keyboard shortcut key that moves the input focus to the control.

BackColor property

Sets or returns the background color of the control.

BorderColor property

Sets or returns the border color of the control.

BorderStyle property

Sets or returns the style of border for the control, in other words, solid, dotted, double, and so on.

BorderWidth property

Sets or returns the width of the control border.

ClientID property

Returns the control identifier that is generated by ASP.NET.

Controls property

Returns a ControlCollection object containing references to all the child controls for this control within the page hierarchy.

Enabled property

Sets or returns a Boolean value indicating whether the control is enabled.

EnableViewState property

Sets or returns a Boolean value indicating if the control should maintain its viewstate and the viewstate of any child controls when the current page request ends.

Font property

Returns information about the font used in the control.

ForeColor property

Sets or returns the foreground color used in the control, usually the color of the text.

Height property

Sets or returns the overall height of the control.

ID property

Sets or returns the identifier specified for the control.

Page property

Returns a reference to the Page object containing the control.

Parent property

Returns a reference to the parent of this control within the page hierarchy.

Style property

References a collection of all the CSS style properties (selectors) that apply to the control.

TabIndex property

Sets or returns the position of the control within the tab order of the page.

ToolTip property

Sets or returns the pop-up text displayed when the mouse pointer is over the control.

Visible property

Sets or returns a Boolean value indicating whether the control should be rendered in the page output.

Width property

Sets or returns the overall width of the control.

DataBind() method

Causes data binding to occur for the control and all its child controls.

FindControl() method

Searches within the current container for a specified server control.

HasControls() method

Returns a Boolean value indicating whether the control contains any child controls.

DataBinding() event

Occurs when the control is being bound to a data source.

The Specific Web Form Control Classes

Each of the Web Form controls inherits from WebControl (or from another control that itself inherits from WebControl), and adds its own task-specific properties, methods, and events. Those commonly used (for each control) are listed in the following table:

Control

Properties

Events

HyperLink

ImageUrl, NavigateUrl, Target, Text

- none -

LinkButton

CommandArgument, CommandName, Text, CausesValidation

OnClick(), OnCommand()

Image

AlternateText, ImageAlign, ImageUrl

- none -

Panel

BackImageUrl, HorizontalAlign, Wrap

- none -

Label

Text

- none -

Button

CommandArgument, CommandName, Text, CausesValidation

OnClick(), OnCommand()

TextBox

AutoPostBack, Columns, MaxLength, ReadOnly, Rows, Text, TextMode, Wrap

OnTextChanged()

CheckBox

AutoPostBack, Checked, Text, TextAlign

OnCheckedChanged()

RadioButton

AutoPostBack, Checked, GroupName, Text, TextAlign

OnCheckedChanged()

ImageButton

CommandArgument, CommandName, CausesValidation

OnClick(), OnCommand()

Table

BackImageUrl, CellPadding, CellSpacing, GridLines, HorizontalAlign, Rows

- none -

TableRow

Cells, HorizontalAlign, VerticalAlign

- none -

TableCell

ColumnSpan, HorizontalAlign, RowSpan, Text, VerticalAlign, Wrap

- none -

Literal

Text

- none -

PlaceHolder

- none -

- none -


No comments: