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 Compare Validator

While the ability to ensure the user has made some sort of entry is great, you will often want to validate that the entry content is within certain guidelines. A common requirement is to compare the user's input to a constant value, the value of another control, or a database value.

To see this at work, make a new copy of the RequiredValidationSummary web site and name the new web site CompareValidator. In this example, you'll add a new control that asks the user how many packages he expects to receive as part of a shipment.

To do so, just insert a text box (call it txtNumPackages), a required field validator, and a compare validator into a new table row before the row that contains the Submit button. You can do this in either Source view or Design view, although the latter makes it very easy.

Switch to Design view and hover your mouse at the left edge of the table row containing the Submit button. Click on the Smart Tag that appears to select the row, as shown in Figure 5-4.

Hovering over the Smart Tag for a table row in Design view allows you to select the row in preparation for inserting a new row above the selected row.

Figure 5-4. Hovering over the Smart Tag for a table row in Design view allows you to select the row in preparation for inserting a new row above the selected row.

From the IDE menus, click on the Layout → Insert → Row Above. This will insert a blank HTML table row above the selected row. Now drag the relevant controls from the Toolbox into the correct table cells. The table now looks like Figure 5-5 ...

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