O'Reilly logo

Learning ASP.NET 2.0 with AJAX by Dan Hurwitz, Jesse Liberty, Brian MacDonald

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

The RequiredFieldValidator

The RequiredFieldValidator ensures the user provides a value for your control, or in the case of drop drop-down lists, that the user picks something other than the default value.

To get started, create a new web site called RequiredFieldValidator. In this section, you're going create the shipping selection web page shown in Design view in Figure 5-1. This is a pretty standard shipping form, as you can see on any number of web sites. You can imagine how you'd incorporate such a page into your own site.

Tip

This new web site can use the normal ASP.NET Web Site template rather than the ASP.NET AJAX-Enabled Web Site template. Although ASP.NET validation controls do much of their work client-side using JavaScript, they neither use nor depend on the AJAX libraries.

This shipping selection page incorporates RequiredFieldValidator controls to ensure that users make selections in each field.

Figure 5-1. This shipping selection page incorporates RequiredFieldValidator controls to ensure that users make selections in each field.

When the user clicks the Submit button, the page is validated to ensure that each field has been modified. If not, the offending field is marked with an error message in red, as shown in Figure 5-2.

You'll use a 3-column, 5-row HTML table to create the page layout, into which you'll place the necessary controls. Using what you've learned from the previous chapters, you can create the table fairly easily, either directly in Source view, or using the Table Wizard, so we won't ...

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