I have a CustomValidator that is being used to check username availability, but it isn’t getting called (I also checked it with a breakpoint).
<asp:CustomValidator ID="usernameC" runat="server" ErrorMessage="Username is already taken" ControlToValidate="txtUsername" Display="None" OnServerValidate="usernameC_ServerValidate" />
Code-behind
protected void usernameC_ServerValidate(object source, ServerValidateEventArgs args)
{
if (new UsersBL().SearchUserByUsername(args.Value) == null)
args.IsValid = true;
else
args.IsValid = false;
}
What may be the problem?
it will be called when the page is being posted to the server. e.g. you have an asp:button and when the user click it the page is sent to the server and before it calls the button_click event it calls the server validation function.