Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using a CustomValidator to check two controls

Posted on 2014-04-02
1
Medium Priority
?
250 Views
Last Modified: 2014-04-03
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;
        }
0
Comment
Question by:CarmenMTorres
1 Comment
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 39973195
don't return

instead:
 if (s2.IndexOf(s1) != -1)
       args.IsValid = false;
else
       args.IsValid = true;

Open in new window

in your save function:

cuvPassword.Validate();

if (cuvPassword.IsValid)
 save();

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question