The RequiredFieldValidator Control

The RequiredFieldValidator is by far the simplest validator control to use. The Required FieldValidator will find a control invalid if the value the user entered is equal to the InitialValue attribute. The InitialValue attribute is the value contained in the control that is to be validated (ex:TextBox) when the page is first rendered to the client. If an InitialValue is not specified, then the value defaults to String.Empty (an empty string). For example, if you have a TextBox control with a RequiredFieldValidator and you don't set the InitialValue attribute, then the Page will not be valid until the user adds at least one character. A code example using the RequiredFieldValidator can be found in Listing 9.4 ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.