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 ...
Get Programming Visual Basic 2005 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.