Vb.net 自定义验证程序OnserverValidate调用类函数
我试图在ServerValidate上为自定义验证器调用cetralized类函数,所以我不必在每个页面上都编写它。我该怎么做Vb.net 自定义验证程序OnserverValidate调用类函数,vb.net,Vb.net,我试图在ServerValidate上为自定义验证器调用cetralized类函数,所以我不必在每个页面上都编写它。我该怎么做 提前谢谢 您可以创建一个模块或类,其中包含一个共享函数作为servervalidate函数。您必须手动添加事件的处理程序: aspx: 可重用验证程序类: Public NotInheritable Class ValidatorUtil Public Shared Sub myFunction(ByVal source As Object, ByVal arg
提前谢谢 您可以创建一个模块或类,其中包含一个共享函数作为servervalidate函数。您必须手动添加事件的处理程序: aspx: 可重用验证程序类:
Public NotInheritable Class ValidatorUtil
Public Shared Sub myFunction(ByVal source As Object, ByVal args As ServerValidateEventArgs)
'validate here and set IsValid'
args.IsValid = False
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
AddHandler Me.CustomValidator1.ServerValidate, AddressOf ValidatorUtil.myFunction
End Sub
Public NotInheritable Class ValidatorUtil
Public Shared Sub myFunction(ByVal source As Object, ByVal args As ServerValidateEventArgs)
'validate here and set IsValid'
args.IsValid = False
End Sub
End Class