I have to do something wrong. It seems I can not execute my CustomValidator ServerValidate method.
I have an ASP.NET Visual Basic page with CustomValidator ...
<asp:TextBox ID="TextBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Friendly message goes here."
Display="Dynamic" />
<asp:Button ID="Button1" runat="server"
Text="Submit"
CausesValidation="True" />
For this test, I have a validation set that always fails ...
Sub CustomValidator1_ServerValidate (ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
args.IsValid = False
End sub
But when the button is clicked, the CustomValidator1_ServerValidate () method is never executed!
Protected Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Page.Validate ()
If Page.IsValid Then
'it executes the code here!
End if
End sub
...
CustomValidator1.Validate() 'does nothing?
?