[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using a CustomValidator to check two controls

Posted on 2014-04-02
1
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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