Validation 如何将一个错误提供程序应用于所有空文本框VB.net 2010
我有这段代码,为每个文本框分配了太多的错误提供程序。是否有其他方法(或更短的方法)专门用于将一个错误提供程序设置为所有文本框Validation 如何将一个错误提供程序应用于所有空文本框VB.net 2010,validation,error-handling,textbox,string,Validation,Error Handling,Textbox,String,我有这段代码,为每个文本框分配了太多的错误提供程序。是否有其他方法(或更短的方法)专门用于将一个错误提供程序设置为所有文本框 If txtHolidayName.Text = "" Then ErrorProvider2.Clear() ErrorProvider3.Clear() ErrorProvider1.SetError(txtHolidayName, "Holiday name is required!") txtHolidayName.Focus()
If txtHolidayName.Text = "" Then
ErrorProvider2.Clear()
ErrorProvider3.Clear()
ErrorProvider1.SetError(txtHolidayName, "Holiday name is required!")
txtHolidayName.Focus()
ElseIf dtpHoliday.Value < Date.Today And txtHolidayName.Text <> "" Then
ErrorProvider1.Clear()
ErrorProvider3.Clear()
ErrorProvider2.SetError(dtpHoliday, "Holiday date must be greater than the current date!")
dtpHoliday.Focus()
ElseIf txtHolidaySalary.Text = "" And dtpHoliday.Value > Date.Today Then
ErrorProvider1.Clear()
ErrorProvider2.Clear()
ErrorProvider3.SetError(txtHolidaySalary, "Holiday salary is required!")
txtHolidaySalary.Focus()
如果txtHolidayName.Text=”“,则
ErrorProvider2.Clear()
ErrorProvider3.Clear()
ErrorProvider1.SetError(txtHolidayName,“需要假日名称!”)
txtHolidayName.Focus()
ElseIf dtpHoliday.ValueDate。然后是今天
ErrorProvider1.Clear()
ErrorProvider2.Clear()
ErrorProvider3.SetError(txTolidaySalary,“需要假日工资!”)
txtHolidaySalary.Focus()
看看这个
Private Sub TextBox_Validating( sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating, TextBox2.Validating, ComboBox1.Validating
Dim ctl As Control = CType(sender, Control)
If ctl.Text = ""
e.Cancel = True
ErrorProvider1.SetError(ctl,"Please enter a value")
End If
End Sub
在私有子部分-将textbox2.validating更改为控件名称。然后使用此函数调用此函数
ErrorProvider1.Clear()
If Me.ValidateChildren()
' continue on
End If
不是我干的。约翰·科纳做到了。这是链接