Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:18:24+00:00 2026-05-25T02:18:24+00:00

The following code is used to validate when form submit button is hit, but

  • 0

The following code is used to validate when form submit button is hit, but I am not getting the wanted result back.

It should display the error messages but they are not being displayed what am I doing wrong?

The custom validator validates passwords, it should change the error message based on the which errors occur:

  1. Password is blank
  2. Password is invalid
  3. Passwords do not match

Only one error should show at a time so I wrote this custom validtor in .ascx.cs:

    protected void cvPasswordValidation_ServerValidate(object source, ServerValidateEventArgs args)
    {

        bool IsPasswordBlank = false;
        bool IsPasswordValid = false;

        cvPasswordValidation.IsValid = false;

        // If password is blank then IsValid is false, show blank password errors.
        if (String.IsNullOrEmpty(args.Value))
        {

            //args.IsValid = false;
            IsPasswordBlank = true;
            //Show blank password error depending on which box is empty.
            if (String.IsNullOrEmpty(txtPassword.Text))
            {
                cvPasswordValidation.ErrorMessage = "You must enter password";
            }
            else
            {
                cvPasswordValidation.ErrorMessage = "You must confirm password";
            }
            cvPasswordValidation.IsValid = false;

        }
        else
        {
            cvPasswordValidation.IsValid = true;
        }

        // If password is not valid format then IsValid is false, show invalid format errors.
        if (!Regex.IsMatch(args.Value, RegexHelper.ValidPassword)) 
        {

            IsPasswordValid = true;
            //Show invalid format errors, if password is not blank
            if (IsPasswordBlank == false)
            {
                cvPasswordValidation.ErrorMessage = "<b>Current password</b> not in correct format. Your password must contain 6 - 12 characters with a combination of numbers and letters.";
            }
            cvPasswordValidation.IsValid = false;
        } 
        else 
        {
            cvPasswordValidation.IsValid = true; 
        } 

        // If passwords do not match then IsValid is false, show do not match errors.
        bool areEqual = String.Equals(txtPassword.Text, txtConfirmPassword.Text, StringComparison.Ordinal);

        if (areEqual == false)
        {

            //Show do not match errors is password is not blank and is not invalid format
            if (IsPasswordBlank == false && IsPasswordValid == false)
            {
                cvPasswordValidation.ErrorMessage = "Your passwords do not match.";
            }
            cvPasswordValidation.IsValid = false;
        }
        else
        {
            cvPasswordValidation.IsValid = true;
        }

    }

and the .ascx:

<asp:TextBox runat="server" ID="txtPassword" MaxLength="12" autocomplete="off" TextMode="Password" ValidationGroup="vgOnlineDetails"></asp:TextBox>

<asp:CustomValidator ID="cvPasswordValidation"
                 runat="server"
                 display="Dynamic"
                 OnServerValidate="cvPasswordValidation_ServerValidate"
                 ControlToValidate="txtPassword"
                 ValidationGroup="vgOnlineDetails">
</asp:CustomValidator>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:18:24+00:00Added an answer on May 25, 2026 at 2:18 am

    You need to set ValidateEmptyText = true to validate empty fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is being used to disable a Submit button once it has
I swear the following code used to work, even in IE7 but now i
I used following code, but it displays only 2 digit of ISO country name.
I used the following code: <script type=text/javascript> function validate() { if ((document.changepass.newpassword.value != '')
I'm making a signup form in which i've used following function for validate signup
When I had used following code, I got the message Failed to validate oauth
I used the following code to put a watermark, this is located at but
here the following code is used to view the present modal view controller. [[self
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.