Form Validation Controls
The ASP.NET Web Forms page framework provides a set of validation server controls that provide an easy-to-use
but powerful way to check input forms for errors, and, if necessary, display messages to the user.
Validation controls are added to an ASP.NET page like other server controls. There are
controls for specific types of validation, such as range checking or pattern matching,
plus a RequiredFieldValidator that ensures that a user does not skip an entry field.
The following example demonstrates how to use two <asp:requiredfieldvalidator runat=server> controls
on a page to validate the contents of the TextBox and DropDownList controls.
Note that the validation controls have both uplevel and downlevel client support. Uplevel
browsers perform validation on the client (using JavaScript and DHTML) and on the server. Downlevel
browsers perform the validation only on the server. The programming model for the two scenarios
is identical.
Note that ASP.NET page developers can optionally check the Page.IsValid property at run time to determine whether all
validation server controls on a page are currently valid. This provides a simple way to determine
whether or not to proceed with business logic. For example, the following sample performs a Page.IsValid check before
executing a database lookup on the specified category.
Code-Behind Web Forms
ASP.NET supports two methods of authoring dynamic pages. The first is the method shown in the preceding samples, where the page code is physically declared within the originating .aspx file. An alternative approach--known as the code-behind method--enables the page code to be more cleanly separated from the HTML content
into an entirely separate file.
The following sample demonstrates the use of the code-behind method of writing ASP.NET page code.
- ASP.NET Web Forms provide an easy and powerful way to build dynamic Web UI.
- ASP.NET Web Forms pages can target any browser client (there are no script library or cookie requirements).
- ASP.NET Web Forms pages provide syntax compatibility with existing ASP pages.
- ASP.NET server controls provide an easy way to encapsulate common functionality.
- ASP.NET ships with 45 built-in server controls. Developers can also use controls built by third parties.
- ASP.NET server controls can automatically project both uplevel and downlevel HTML.
- ASP.NET templates provide an easy way to customize the look and feel of list server controls.
- ASP.NET validation controls provide an easy way to do declarative client or server data validation.
Copyright 2001 Microsoft Corporation. All rights reserved.