The Compare Validator
While ensuring that the user has made an entry is very useful, you will often want to validate that the content of the entry is within certain guidelines. One of the most common requirements for validation is to compare the user's input to a constant, the value of another control, or a database value.
Add a new control to your bug-reporting dialog that will ask the user how many copies of the book he purchased. Manually type in a new row (using <tr><td> tags) above the Display Errors row, and set the prompt column to Number purchased:. The second column needs a text box (txtNumPurch), and the third column now takes two validators (just drag them both into the same column).

Figure 9-11. Summary and BulletList

Figure 9-12. Message box with List
The validator first is a RequiredFieldValidator (ID = reqFieldNumPurch and Control-ToValidate=txtNumPurch.
The RequiredFieldValidator ensures that the user does not leave the entry blank. Finally, set its ErrorMessage property to Please enter the number of books purchased, and its Text property to an asterisk.
The second validator is of type CompareValidator
(which you also find in the Validation tab in the Toolbox). You'll use this validator to ensure that the user does not enter the value zero. The properties of the CompareValidator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access