Lesson 2: Using Validation
The purpose of this lesson is to detail the validation controls in ASP.NET.
- "Client-side validation is provided by a JScript library named WebUIValidation.js, which is downloaded separately to the client."
It is important to note that the client-side validation features in ASP.NET work only in Microsoft Internet Explorer version 4.0 and later. This is why validation controls automatically provide server-side validation. (Incidentally, the sample Web form Validation1.aspx uses a call to Server.Transfer() that breaks the automatic server-side validation functionality.)
The validation controls: RequiredFieldValidator, CompareValidator, RangeValidator, RegularExpressionValidator, CustomValidator and ValidationSummary.
- "A server control can have multiple validators."
The lesson details a problem (in Table 4-7) with the CompareValidator control that can be solved by combining it with a RequiredFieldValidator control.
- "To let the user cancel validation, provide a Submit HTML control that sets the Page_ValidationActive attribute..."
Clicking on this Submit HTML control will cause a postback and in the Page_Load event procedure below, the variable bln will be false:
bool bln;
if(this.IsPostBack)
{
this.Validate();
bln = this.IsValid;
}
There is a typo in this lesson stating effectively that bln would be true.
- "Customizing Validation... On the server side, place your validation code in the ServerValidate event procedure... To provide client-side validation, specify a validation script in the CustomValidator control's ClientValidationFunction property."
This may be one of very few places where an external JavaScript file could seamlessly integrate with an ASP.NET Web form design pattern.