Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 自定义验证程序OnserverValidate调用类函数_Vb.net - Fatal编程技术网

Vb.net 自定义验证程序OnserverValidate调用类函数

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上为自定义验证器调用cetralized类函数,所以我不必在每个页面上都编写它。我该怎么做


提前谢谢

您可以创建一个模块或类,其中包含一个共享函数作为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