We have been developing a website to automate a question and reply process that I've called AVBAsk. One of the things that it doesn't do is validate data. It's time to fix that.
One of the control groups available for ASP.NET web pages is the Validation controls. It's a very good idea to make sure that data is as correct as possible before doing anything with it. So ASP.NET provides a selection of very flexible controls to do just that.
These controls are placed on the web page where you want an error message to be displayed if the validation fails. The Display property (None / Static / Dynamic) determines whether space is reserved for the message in the form. None allows the messages to be displayed by the ValidationSummary control. Static reserves space and Dynamic creates the space as needed. This example uses Dynamic to show how that works.
Since a message with no text is not allowed, a RequiredFieldValidator control has been added to the end of the form. Display is set to Dynamic and a message is typed into the ErrorMessage property. Most important, the ControlToValidate property is set to the name of the message TextBox, AVBMessage.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The email address is more interesting. ASP.NET provides the capability to check strings for validity using Regular Expressions. If you want to know more about them, check out the About Visual Basic article, Regular Expressions in VB.NET.
A RegularExpressionValidator control is added to the form next to the first one. ASP.NET gives you a selection of common regular expressions to use. If the text entered into the email TextBox isn't a valid email address, this expression returns a value that triggers the display of the error message.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Note that the invalid email address message appears on the left margin in spite of the fact that it's behind the other message due to the Dynamic value in the Display property.
Make sure you save this website so we can pick up at this point in future lessons where we add more functions! The code will be updated in part 5, Code-Behind and Database Updating.

