You do not give an environment, but I assume it is WinForms. On all events there is a sender. You can determine which control sent the event by using the sender, and you can cast it to the right type (in this case
var tb = (TextBox)sender
.
You can do the Validating
void TextBox_Validating(object sender, CancelEventArgs e) {
if( TextBox.Text.Length == 0 )
{
MessageBox.Show("Please enter a name", "Error");
e.Cancel = true;
}
}
All you need to do is target all the text box events to the same handler.
A quick overview is at
http://www.sellsbrothers.com/writing/winformsDataValidation.htm[
^]