I have the following piece of asp:
<asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup"/>
...
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserNameTB">Username:</asp:Label>
<asp:TextBox ID="UserNameTB" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="UserNameTB"
ValidationExpression="[a-zA-Z]{3,8}" ErrorMessage="Username must be between 3 to 8 chars" runat="server"
CssClass="failureNotification" ToolTip="Username must be between 3 to 8 chars" ValidationGroup="RegisterUserValidationGroup">
*</asp:RegularExpressionValidator>
<asp:CustomValidator ID="NoUserValidator" ControlToValidate="UsernameTB" runat="server" ErrorMessage="User Taken!" CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup" OnServerValidate="UserValidate">*</asp:CustomValidator>
And then the function:
protected void UserValidate(object source, ServerValidateEventArgs args)
{
SqlDataSource1.SelectCommand = "SELECT ClientID FROM [Clients] WHERE Username= '" + UserNameTB.Text + "'";
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
if (dv.Table.Rows.Count != 0)
args.IsValid = false;
else
args.IsValid = true;
}
Button:
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User"
ValidationGroup="RegisterUserValidationGroup"
onclick="CreateUserButton_Click"/>
Problem is that even though the custom validator function is called and sets .IsValid
to false,
the button logic still runs!