I defined a customvalidator that checks that the first control (USERID) is not part of the second control (PASSWORD). If it is then an error message is displayed indicating that password cannot be made up of the UserID. This logic is run at the server-side.
When I test my logic, the system displays the error message and proceeds to save the record to the database. Eventhough, I specified the args.IsValid to be false, the record is still written to the database. Can anyone help me at getting the system not to save the record if the function failed? Thank you.
Below is snippet of my code:
(located in the ASPX file)
<asp:CustomValidator ID="cuvPassword" runat="server"
ErrorMessage="Password cannot contain User ID"
OnServerValidate="CheckIfIdInPswd"
Display="None" ValidationGroup="vsShow">*</asp:CustomValidator>
(located in the ASPX.CS file)
protected void CheckIfIdInPswd(object source, ServerValidateEventArgs args)
{
string s1 = this.txtUserId.Text;
string s2 = this.txtPassword.Text;
if (s2.IndexOf(s1) != -1)
{
args.IsValid = false;
return;
}
args.IsValid = true;
}
instead:
Open in new window
in your save function:Open in new window