CProgrammingTrends Home Page About iEntry Article Archive News WebProWorld Forums Jayde iEntry Contact Advertise Downloads iEntry
04.07.04

Using Error Provider Control In Windows Forms And C#

By Dipal Choksi

In this example we will see how to use the ErrorProvider control in Windows forms to provide validations in Windows Forms and display user-friendly error messages to the user if the validation fails.

Figure : Error Provider Sample

The complete code listing is provided at the end of the sample.

Create a new Visual C# Windows Forms application. The project will create a default form Form1.cs. Add controls as shown in the figure below and set the properties of the controls as indicated in the table.



Figure : Sample Form Layout




Table : Properties for Sample Form Layout Controls

Now add a ErrorProvider control to the Form. In Visual Studio.Net, you can drag and drop the control from the toolbox. The control is added to the form and displayed in the control tray in the Windows form in Design view. If you are not using Visual Studio.Net, then you can add the control in the code. Please refer to the code listing provided at the end of the article.

Now create an event handler for the “Validating” event of the textBox1 control. We will validate the TextBox to ensure that the user has entered a value.




Code Snippet: Validate the Name TextBox

Next we will add the validations for the textBox2 control which accepts Age as the data input. We will ensure that the Age is mandatory, is in numeric format and the user is 18 years or older.



Read the Full Article


About the Author:
Dipal Choksi is a Bachelor of Engineering (Computer Science). She has industry experience in team-effort projects and also as an individual contributor. She has worked on Visual Basic, Visual C++, Java, Directory Services, ASP projects


Read this Newsletter at: http://www.cprogrammingtrends.com/2004/0407.html
Free Newsletters
Part of the iEntry Network
over 4 million subscribers
CProg.Trends
SecurityConfig
ITProNews

Send me relevant info on products and services.


 

 

From the Forum:
script for timed website
Hello, I really enjoy reading the messages posted here. I am wondering if someone can help me. I have a password protect area on a web site (created with Front Page) and I want this site to close all windows after a certain amount of time. I now have a redirect after 5 minutes but someone can easily hit the back button and get right back to the "secured" area.
Go Here

 

 

 

-- CProgrammingTrends is an iEntry, Inc. publication --
iEntry, Inc. 880 Corporate Drive, Lexington, KY 40503
2004 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article

DevNewz.com SecurityProNews.ocm