我编写了一个函数来检查表单上的任何文本框是否为空.如果我将它添加到TextBox'leave'事件,它目前有效.
我尝试将其添加到按钮单击事件但它给出了一个错误(NullReferenceException unhandled).
以下是代码:
public void inputBlank(object sender, EventArgs e)
{
TextBox userInput;
userInput = sender as TextBox;
userTextBox = userInput.Text;
string blankBoxName = userInput.Name;
string blankBox = blankBoxName.Remove(0,3);
if (userTextBox == "")
{
errWarning.SetError(userInput, "Please enter a value for " + blankBox);
userInput.Focus();
}
else
{
errWarning.SetError(userInput, "");
}
}
Run Code Online (Sandbox Code Playgroud)
只是想知道你是否可以建议我如何解决它.
非常感谢.