我有一个 Windows 窗体应用程序并正在调用ErrorProvider.Dispose
以清除错误文本。但是,当我第二次调用它时它不起作用(即,如果文本框为空,ErrorProvider
则会显示,但在我填充文本框并再次按下提交按钮后,它不会显示错误)。
我有一个包含许多文本框的表单,我只是在单击提交按钮后检查字段是否为空:
foreach (Control c in this.college.Controls)
{
if (c is TextBox)
{
TextBox textBox = c as TextBox;
if (textBox.Text.Equals(string.Empty))
{
if (string.IsNullOrWhiteSpace(textBox.Text))
{
errorProvider1.SetError(textBox, "Field Empty");
}
else
{
errorProvider1.Dispose();
}
}
}
}