以下是自定义验证码
<asp:CustomValidator ID="ModelValidator" runat="server"
ErrorMessage="Model is required."
ForeColor="Red" ValidateEmptyText="true"
OnServerValidate="Model_Validate" ></asp:CustomValidator>
背后的代码
Protected Sub Model_Validate(source As Object, args As ServerValidateEventArgs) Handles ModelValidator.ServerValidate
Dim value As String = txtModel.SelectedItem.Text
If value = "--None--" Then
args.IsValid = False
End If
End Sub
答案 0 :(得分:1)
您应该检查page.IsValid
,如下所示:
Protected Sub Model_Validate(source As Object, args As ServerValidateEventArgs) Handles ModelValidator.ServerValidate
If Page.IsValid Then
Dim value As String = txtModel.SelectedItem.Text
If value = "--None--" Then
args.IsValid = False
End If
End If
End Sub