0

Checking whether value is entered into a control and preventing focus to go out if no value is entered.

private void txtName_Validating(object sender, CancelEventArgs e)
{
    if (txtName.Text == "")
    {
        errorProvider1.SetError(txtName, "Name cannot be blank");
        e.Cancel = true;
    }
    else
        errorProvider1.SetError(txtName, "");
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by bruceraymond
0

C# has internal parsing routines that also work nicely.

Cheers,
Bruce

double x;
bool valid = double.TryParse( initialValue.Text, out x );
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.