I have an UserControl CambioContraseña with two textBox of other customized UserControl called txtAlfanumerico. This UserContol is very simple but I want to add an ErrorProvider to check the fields are not empty. This is a screen capture of UserControl:
And this is an code:
public bool FaltaCampos() {
bool falta = false;
foreach(txtAlfanumerico txt in Controls.OfType < txtAlfanumerico > ()) {
if (txt.Text == "") {
errorProviderFalta.SetError(txt, "Falta " + txt.Tag.ToString());
falta = true;
} else {
errorProviderFalta.SetError(txt, "");
}
}
return falta;
}
And the code in where I use this UserControl:
private void buttonConfirmar_Click(object sender, EventArgs e) {
try {
if (!cambioContraseña1.FaltaCampos()) {
string actual = cambioContraseña1.TextBoxContraseñaActual();
string nueva = cambioContraseña1.TextBoxNuevaContraseña();
persona.CambiarContraseña(actual, nueva);
}
} catch (Exception ex) {
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
But my problem is that ErrorProvider do not work in the Form that I use, icons do not appear directly.
I did a breakpoint into FaltaCampos and these are results:


I can to resolve my problem I think that I had not compiled the UserControl when I did the changes, so the ErrorProvider didn't appear.