Visual C# | Validating forms exercise | ErrorProvider controls to check age filled in

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the course listed below!

Software ==> Visual C#  (79 exercises)
Version ==>
Topic ==> Validating forms  (6 exercises)
Level ==> Average difficulty
Course ==> WinForms using Visual C#
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Add the form in the above folder to your application, or work with a copy of this form that you have already imported or created.

Add an ErrorProvider control to your form.

Attach code to the Validating event of each of the two text boxes so that:

  • if the length of the name is zero, you show an error next to it
  • if the age isn't an integer, you show an error next to it

Test out your validation:

Visual C Sharp 2005 exercise - Validating forms (image 1)

This shows that you need to be careful when displaying errors next to textbox controls in panels

Check that your application works, then close down its forms.

This page has 0 threads Add post