O'Reilly logo

ASP.NET by Example by Steven A. Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inserting a Validation Control

Inserting a validation control is no different from inserting any other control. If you are using Visual Studio .NET, you can simply drag the appropriate control onto your page's layout. Otherwise, simply insert the appropriate control within the HTML where you would like the validation's message to appear if the input is not valid. The following example demonstrates how to require a user to enter his or her name.

Perhaps the most common form of validation is simply to require that fields be filled in. The RequiredFieldValidator control does just this. Listing 8.1 shows the relevant code to make a text box entry required (that is, to ensure that the user enters some value).

Listing 8.1. Adding required validation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required