Reputation: 223
I have a button and a textbox, i want to check if the textbox validation is correct and passed correctly when i click on the button. else the user should recieve a warning to check again what he had write in the textbox.
Upvotes: 0
Views: 1100
Reputation: 1935
public bool Validations()
{
if (string.IsNullOrEmpty(Textbox.Text))
{
MessageBox.Show(" Error ");
return false;
}
else
{
// your code
}
}
private void button1_Click(object sender, EventArgs e)
{
if (!Validations())
return;
}
Upvotes: 1
Reputation: 952
Try using ErrorProvider. It may help.
private void button1_Click(object sender, EventArgs e)
{
// check if something is wrong
errorProvider1.SetError(textBox1,"Some Error!");
}
Upvotes: 0