Library code snippets
Data Entry Validation with Error Provider
To use this code, simply drag the errorProvider control onto the form, it appears in the list as a red exclamation mark. Add one textbox and one command button, now use this code in the button click event private void button1_Click(object sender, System.EventArgs e)
{
//CHECK FOR DATA ENTRY
if(textBox1.Text =="")
{
//NO DATA!
errorProvider1.SetError(textBox1,"You need to enter a value");
} else
{
//DATA ENTERED DONT SHOW THE ERROR WITH ""
errorProvider1.SetError(textBox1,"");
}
}
You set the error icon active if the data validation is not meet, in this case its if there is no text in the textbox, to hide the errorprovider again simply just include "" instead of putting text in the seterror. You can set the BlinkStyle of the provider to NeverBlink, AlwaysBlink and BlinkIfDifferentError.You can set those by the properties view in design time or in code in runtime. You can also change the icon at design time to whichever icon you like.
Related articles
Related discussion
-
how to select multiple files at a time using Ctrl+select and upload the attachments in C# .Net 1.0?
by vasanta (0 replies)
-
Help please for student
by mandy130 (0 replies)
-
Loop help needed
by BKRoberts (5 replies)
-
Problem after strong naming an assembly
by rinkurathor1 (0 replies)
-
Regarding User control creation in C# .Net(Windows Application)
by porchelvi (0 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
Comments
Leave a comment
Sign in or Join us (it's free).