Users Pricing

articles

home / developersection / articles / errorprovider control in c#.net

ErrorProvider Control in C#.Net

Anonymous User 18143 24 Jan 2011 Updated 04 Mar 2020

ErrorProvider simplifies and streamlines error presentation. It is an abstraction that shows errors on your form. It does not require a lot of work on your part. This is its key feature.

How to use ErrorProvider Control

Drag and drop ErrorProvider ,TextBox and Button  control from toolbox on the window Form.


ErrorProvider Control  in C#.Net

ErrorProvider Control  in C#.Net

Code:

Write code on Button click event.

ErrorProvider Control  in C#.Net

Double click on Click event.

private void btnSubmit_Click(object sender, EventArgs e)
{
          if (textBox1.Text == "")//condition is given so that empty textbox could not save
            {
            errorProvider1.SetError(textBox1, "Cannot leave textbox blank");
                //error text will show as tooltip
            }
           else
            errorProvider1.SetError(textBox1, "");
         label3.Text = "Entered name is " + textBox1.Text;
}

Run The Project

ErrorProvider Control  in C#.Net

If textbox is empty and Submit button is clicked then error icon will display.

ErrorProvider Control  in C#.Net

When name is entered in textbox and Submit button clicked then entered name will show in Label.

ErrorProvider Control  in C#.Net

ErrorProvider Property:

Icon property:   which allows us to set an icon that will be display when error occurred?

BlinkRate property:   which allows setting the rate in milliseconds at which the icon blinks.

Icon:    Set the Icon that is displayed next to a control when an error occurred. 

BlinkStyle:   Gets or sets a value indicating when the error icon flashes



I am a content writter !


2 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md