c# - 有没有办法只为取消按钮覆盖验证事件?
问题描述
我试图为 ID 文本框添加一个验证事件,以确保在提交表单时,用户必须填写 ID 文本框。表单还有一个取消按钮来关闭表单。
关闭按钮执行此操作this.Close();
但现在问题是即使我单击取消按钮,验证事件也在执行。我想要一种方法来解决这个问题。
下面是代码。
//This is the code for my Cancel button
private void btnCancel_Click(object sender, EventArgs e)
{
CausesValidation = false;
this.Close();
}
//This is the code for my Validating event
private void tbID_Validating(object sender, CancelEventArgs e)
{
/*if Supplier name and Company name filled user can't go forward without filling Supplier ID*/
if (string.IsNullOrEmpty(tbID.Text))
{
e.Cancel = true;
errorProviderID.SetError(tbID, "You can not leave supplier ID empty");
}
else
{
errorProviderID.Clear();
}
}
解决方案
推荐阅读
- c - 如何限制对 FILE 的访问被 C 中的另一个进程或函数使用(写入/读取)?
- sql - 两次加入同一个表时得到重复值
- npm - 在 npm 包中使用 postinstall 是否安全?
- javascript - SAPUI5中元素绑定中的元素绑定
- php - 无法编辑页面正在迁移 wordpress 托管和域 - Error-post.php
- google-analytics - 如何在没有 gtag.js 库的情况下使用 Google Analytics
- android - Android Studio中4个图像按钮的两个ConstraintLayout有什么不同?
- android - 如何使用改造和 kotlin 协程发送获取请求的参数。?
- networking - 网络启动命令
- python - 在整个站点范围内显示查询集计数?