Paula Shenouda
Paula Shenouda

Reputation: 223

validating textbox with a button?

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

Answers (2)

62071072SP
62071072SP

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

PythEch
PythEch

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

Related Questions