JavaScript Editor jscript editor     Web designer 



Main Page

ASP.NET 2.0 includes changes to Web server controls from previous versions as well as introducing numerous new controls and features. This topic discusses both the

general changes to controls as well as new controls and changes to existing controls.

General Control Changes

Themes

You can now use themes to define a consistent look and feel for pages and controls. A theme is a set of elements, including skins, cascading style sheets (CSS), and images, that can be applied to an individual control, a page, or a Web site. For more information, see ASP.NET Themes and Skins Overview.

Validation

Validation controls expose a ValidationGroup property that enables you to specify discrete sets of validation controls that are validated (or not validated) together. You can get references to all of the validation controls for a validation group by calling the GetValidators method.

The Page class now includes an overload to the Validate method that takes a parameter that identifies a validation group. You can call the overload that takes the validationGroup parameter to force validation for only that validation group, or the overload that takes no parameters to force validation for all validation controls on the page.

Additionally, the Page class's IsValid property now considers validation controls only in the current validation group. The current validation group is determined by the control that caused validation to occur. For example, if a button control is clicked and causes validation for the LoginForm validation group, then the IsValid property will return true if all validation controls whose ValidationGroup property is set to LoginForm are valid.

Validation controls also now have a SetFocusOnError property. If the property is true, when a validation error occurs, focus is set to the control identified by the ControlToValidate property.

The CustomValidator class now has a ValidateEmptyText property. If the ValidateEmptyText property is true, the CustomValidator object calls the client-side validation method identified by the ClientValidationFunction property and raises the ServerValidate event even when the value that is being validated is an empty string.

For more information, see Validation ASP.NET Controls.

Data Binding

ASP.NET has a new data binding model that is built on data source controls. Data source controls connect to and retrieve data from a variety of data sources including databases, business objects, and XML, and make the data available for other controls to bind to, without requiring code. They can also support modifying data. Data-bound controls now include a DataSourceID property that identifies the data source control to bind to. For more information, see Data Source Controls Overview.

Additionally, list controls such as the ListBox and DropDownList controls now expose an AppendDataBoundItems property; when this property is set to true, the control combines statically defined list items with items dynamically added by data binding.

Client Callbacks

Several controls, including the TreeView control, support client callbacks, which enable the control to communicate with the server without requiring a full postback.

For more information, see Implementing Client Callbacks Without Postbacks in ASP.NET Web Pages.

Standards Support

ASP.NET controls have been updated to support the XHTML standard as well as standards for accessible applications. For more information, see ASP.NET and XHTML and Accessibility Support in ASP.NET.

New Controls

ASP.NET includes a number of new controls as listed in the following tables.

Standard Controls

BulletedList

Displays items as a bulleted list. Similar to other list controls such as the CheckBoxList or RadioButtonList controls, but renders differently. Bullet style can be set to text, hyperlinks, button controls, and images. Like all list controls, the BulletedList control can be populated using data binding.

For more information, see BulletedList Web Server Control Overview.

FileUpload

Manages file uploads using the HTML <input type="file"> element. Similar to the HtmlInputFile control, but supports additional options for handling uploaded data, including saving it as a file or handling it as stream.

For more information, see FileUpload Web Server Control Overview.

HiddenField

Manages hidden form fields using the HTML <input type="hidden"> element. Similar to the HtmlInputHidden control, but derives from the WebControl base class for added functionality.

For more information, see HiddenField Web Server Control Overview.

ImageField

Displays an image for each record displayed in data-bound controls, such as the GridView and DetailsView controls.

ImageMap, CircleHotSpot, PolygonHotSpot, RectangleHotSpot

Renders an HTML image map. When using the ImageMap control, you define an Image control, then define hotspots (CircleHotSpot, PolygonHotSpot, or RectangleHotSpot objects) as child controls with appropriate sets of coordinates. For each hotspot, you can specify a mode, such as Navigate or PostBack, and related properties, such as the NavigateUrl property when in Navigate mode, or the PostBackValue property when in PostBack mode.

For more information, see ImageMap Web Server Control Overview.

Menu

Used to display a menu in an ASP.NET Web page. Often used in combination with a SiteMapDataSource control for creating Web site navigation.

For information on site navigation, see ASP.NET Site Navigation Overview.

MultiView, View

Generates multi-panel displays where you can conditionally render different views. The MultiView control is the parent control for which you define two or more View controls as children. The View controls contain markup and controls that make up each panel of the display.

NoteNote

For multi-panel displays that walk a user through a specific task, you might want to use the Wizard control instead.

For more information on the MultiView and View controls, see MultiView and View Web Server Controls Overview.

SiteMapPath

Creates a view of a portion of a site's navigation (a "bread crumb") based on information in a site map.

For information on site navigation, see ASP.NET Site Navigation Overview.

Substitution

Specifies a region on a page that can be dynamically filled even when the page has been cached. When using the Substitution control, you define a callback method that returns the data to display.

For more information, see Substitution Web Server Control Overview.

TreeView

Displays hierarchical data, such as a table of contents or file directory, in a tree structure. The TreeView control can be bound to a data source control such as an XmlDataSource or SiteMapDataSource control.

For more information, see TreeView Web Server Control Overview.

Wizard

Enables you to collect user input one step at a time and allows for either linear or nonlinear navigation through the steps.

For more information, see Wizard Web Server Control Overview.

Data Source Controls

ASP.NET now includes data source controls to support code-free data-binding scenarios. The following table describes the built-in data source controls. For more details, see Data Source Web Server Controls.

AccessDataSource

Enables you to work with a Microsoft Access database. Supports sorting, filtering, and paging.

ObjectDataSource

Enables you to work with a business object or other class and create Web applications that rely on middle-tier objects to manage data. Supports advanced sorting and paging scenarios unavailable with the other data source controls.

SiteMapDataSource

Enables navigation controls, such as a Menu control, to read ASP.NET site map information. For more information, see ASP.NET Site Navigation Overview.

SqlDataSource

Enables you to work with Microsoft SQL Server, OLE DB, ODBC, or Oracle databases. When used with SQL Server, supports advanced caching capabilities. Supports sorting, filtering, and paging.

XmlDataSource

Enables you to work with an XML file, especially for hierarchical ASP.NET server controls such as the TreeView or Menu control. Supports filtering capabilities using XPath expressions and enables you to apply an XSLT transformation to the data. The XmlDataSource allows you to update data by saving the entire XML document with changes.

Data-bound Controls

Data-bound controls can be bound to a data source control to make it easy to display and modify data in your Web application. A data-bound control can bind to a tabular set of results such as a dataset or collection or to a single item in a table of results.

NoteNote

Some controls, such as the TreeView, Menu, and SiteMapPath controls can bind to hierarchical data such as an XML file.

Data-bound controls that have shipped with previous releases of ASP.NET include the DataList, Repeater, and DataGrid controls. The DataList and Repeater controls have been updated to bind to the new data source controls included with ASP.NET. Although the DataGrid control is still available, is has been superseded by the GridView control.

The following table lists the new data-bound controls included with ASP.NET. For more information, see ASP.NET Data-Bound Web Server Controls Overview.

GridView

Displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record. The GridView control supersedes the DataGrid control from previous versions of ASP.NET. For more information, see GridView Web Server Control.

DetailsView

Renders a single record at a time and provides the capability to page through data as well as to insert, update, and delete records. The DetailsView control is often used in master-detail scenarios where the selected record in a master control such as a GridView control determines the record displayed by the DetailsView control.

For more information, see DetailsView Web Server Control.

FormView

Renders a single record at a time from a data source, similar to the DetailsView control. However, the difference between the FormView and the DetailsView controls is that the DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own. In contrast, the FormView control does not specify a pre-defined layout for displaying a record. Instead, you create templates containing controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to create the form.

For more information, see FormView Web Server Control.

Login Controls

ASP.NET now includes login controls for use ASP.NET forms authentication and ASP.NET membership. The login controls encapsulate much of the functionality required for an authenticated site, including allowing users to log in, displaying the logged-in user name and related user information, creating a new user, and recovering or resetting a password, without requiring code. Several of the login controls can be customized through the use of templates. The following table lists the login controls with a brief description of each. For more information, see Login ASP.NET Controls.

Login

Displays a user interface for user authentication. By default, the Login control displays text boxes for the user name and password and a check box that allows users to indicate whether the application should remember the user between visits.

LoginName

Displays a user's login name if the user has logged in using ASP.NET membership. Alternatively, if your site uses Integrated Windows authentication, the control displays the user's Windows account name.

LoginStatus

Detects whether a user is logged in. If the user has not yet logged in, displays a login button that takes the user to a login page. If the user is logged in, displays a logout button.

LoginView

Allows you to display a different user interface and templates based on user authentication and authorization (roles).

CreateUserWizard

Collects information for a new user and adds the user to the ASP.NET membership system.

ChangePassword

Allows users to change their password. (The control works only with ASP.NET membership, and does not allow user to change their Windows password.)

PasswordRecovery

Allows user passwords to be retrieved based on the e-mail address that was used when the account was created. The PasswordRecovery control sends an e-mail message containing a password to the user.

Changes to Existing Controls

Controls that were available in previous versions of ASP.NET have been updated with new functionality for data binding, accessibility, and so on. The following table lists the controls and changes made to them for ASP.NET 2.0.

AdRotator

Supports the new data-binding model and can use data source controls for data retrieval (although this requires a specific database schema). The AdRotator control implicitly supports post-cache substitution, meaning it will render unique advertisements on each request, regardless of whether the page is cached.

For more information, see AdRotator Web Server Control Overview.

Button, ImageButton, LinkButton

Supports several new properties inherited from the Button base class.

The OnClientClick property identifies the name of a client-side method to invoke when the button is clicked but before a postback occurs. In client script you can cancel the postback.

The PostBackUrl property allows you to post one ASP.NET page to another page by identifying the URL of the target page.

The UseSubmitBehavior property (available only for the Button control) enables you to specify whether to use the browser's submit mechanism when submitting a page or to post the page using client-side script generated by ASP.NET.

Calendar

Exposes Caption and CaptionAlign properties that write a caption element into the rendered HTML table.

The Calendar control also now has a UseAccessibleHeader property. When this property is set to true, the Calendar control renders day names in HTML table header (th) elements.

The DayRenderEventArgs object used with the DayRender event now includes a SelectUrl property. This returns the client script that is normally used by the LinkButton control for rendering calendar days. You can use the SelectUrl property to customize the format of day links.

For more information, see Calendar Web Server Control Overview.

CheckBox

Supports LabelAttributes and InputAttributes properties that enable you to specify custom attributes for the label and input HTML elements that are rendered by the control, respectively.

For more information, see CheckBox and CheckBoxList Web Server Controls Overview.

CheckBoxList

Supports the new data-binding model and can make use of data source controls for data retrieval.

For more information, see CheckBox and CheckBoxList Web Server Controls Overview.

DataGrid

Supports the new data-binding model and uses data source controls. However, it is recommended that you use the GridView control instead for tabular display of data. The GridView control provides improved support for data-binding scenarios.

For more information on the GridView control, see GridView Web Server Control Overview and Comparing the GridView and DataGrid Web Server Controls.

DropDownList

Supports the new data-binding model and can make use of data source controls for data retrieval.

For more information, see DropDownList Web Server Control Overview.

Image

Exposes a GenerateEmptyAlternateText property that ensures an empty alt attribute is included for the HTML image element rendered by the control. This improves the accessibility of your application for users who use a screen reader.

For more information, see Image Web Server Control Overview.

Label

Exposes an AssociatedControlID property that enables you to link a Label control with another control on the page and act as that control's caption. When users click the rendered HTML label element or use its access key, focus passes to the associated control.

For more information, see Label Web Server Control Overview.

ListBox

Supports the new data-binding model and can make use of data source controls for data retrieval.

For more information, see ListBox Web Server Control Overview.

Literal

Exposes a Mode property that enables you to specify how the control treats HTML markup in its Text property. You can encode the text, let the text pass through unchanged, or transform the text to remove unsupported markup elements for non-HTML or XHTML browsers.

For more information, see Literal Web Server Control Overview.

Panel

Exposes a ScrollBars property that enables you to specify scrollbars for the panel.

Exposes a GroupingText property that you can set to a value that will be used as a title for a box rendered around the panel.

Exposes a DefaultButton property that allows you to specify a default button for the panel. When users press ENTER inside a text box, the default button is invoked.

For more information, see Panel Web Server Control Overview.

RadioButtonList

Supports the new data-binding model and can make use of data source controls for data retrieval.

For more information, see RadioButton and RadioButtonList Web Server Controls Overview.

Table

Exposes Caption and CaptionAlign properties that render a caption element in the rendered HTML table. These properties are available in any Web server control that inherently renders as a table, such as the Calendar and GridView controls.

TextBox

Supports the new AutoCompleteType property, which allows you to specify how the text box will retrieve values in a browser that supports AutoComplete. By default, browsers that support AutoComplete index possible values for a text box based on the ID of the control (the ID is used as the name of the HTML input element). The AutoCompleteType property allows you to use the ID of the control (the default), specify a category of values for the control to use, or disable AutoComplete for the control.

For more information on the AutoComplete feature in Internet Explorer, search for the "Using AutoComplete in HTML Forms" topic on the MSDN Library Web site.

For more information on the TextBox control, see TextBox Web Server Control Overview.

See Also



JavaScript Editor jscript editor     Web designer