Introduction:
Today, we discussed about How to validate Text Box with Error Provider in C#.Net? .
Conditions:
TextBox should enter only integer.
create one validation event for integer
Here the Code:
this.textBox1.Validating += new
Today, we discussed about How to validate Text Box with Error Provider in C#.Net? .
Conditions:
TextBox should enter only integer.
create one validation event for integer
protected void textBox1_Validating (object sender,
System.ComponentModel.CancelEventArgs e)
{
try
{
int x = Int32.Parse(textBox1.Text);
errorProvider1.SetError(textBox1, "");
}
catch (Exception ex)
{
errorProvider1.SetError(textBox1, "Not an integer value.");
}
}
Call this event in constructorSystem.ComponentModel.CancelEventArgs e)
{
try
{
int x = Int32.Parse(textBox1.Text);
errorProvider1.SetError(textBox1, "");
}
catch (Exception ex)
{
errorProvider1.SetError(textBox1, "Not an integer value.");
}
}
this.textBox1.Validating += new
System.ComponentModel.CancelEventHandler(this.textBox1_Validating);