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

  • SEARCH
  • Home
  • 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 7912639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:39:34+00:00 2026-06-03T13:39:34+00:00

I have two textboxes. I need to validate them before taking any other action.

  • 0

I have two textboxes. I need to validate them before taking any other action.

private ErrorProvider _errorProviderEmail = new ErrorProvider();
private ErrorProvider _errorProviderPass = new ErrorProvider();
public FormLogin()
{
  InitializeComponent();

  textBoxEmail.Validating += TextBoxEmailValidating;
  textBoxPass.Validating += TextBoxPassValidating;

  textBoxEmail.Validated += TextBoxEmailValidated;
  textBoxPass.Validated += TextBoxPassValidated;

  textBoxEmail.Text = "";
  textBoxPass.Text = "";
}

void TextBoxPassValidated(object sender, EventArgs e)
{
  _errorProviderPass.SetError(textBoxPass, "");
}

void TextBoxEmailValidated(object sender, EventArgs e)
{
  _errorProviderEmail.SetError(textBoxEmail, "");
}

void TextBoxPassValidating(object sender, System.ComponentModel.CancelEventArgs e)
{
  if (!string.IsNullOrEmpty(textBoxPass.Text)) return;
  e.Cancel = true;
  _errorProviderPass.SetError(textBoxPass,"Password is required!");
}

void TextBoxEmailValidating(object sender, System.ComponentModel.CancelEventArgs e)
{
  if (!string.IsNullOrEmpty(textBoxEmail.Text)) return;
  e.Cancel = true;
  _errorProviderEmail.SetError(textBoxEmail, "Email address is required!");
}

The problem is that only validating event for textBoxEmail is triggered, what could be wrong here, and why the validating event for textBoxPass never fires?

  • 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-06-03T13:39:35+00:00Added an answer on June 3, 2026 at 1:39 pm

    The individual TextBox controls only validate when they lose their focus.

    Try calling the form’s ValidateChildren() function to force each control to call their validation handlers:

    private void button1_Click(object sender, EventArgs e) {
      if (this.ValidateChildren()) {
        this.Close();
      }
    }
    

    Also, you only need one ErrrorProvider component.

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

Sidebar

Related Questions

I have two asp.net textboxes and need to put a validate function in javascript
I have two textboxes, each contain a time (textboxA / textboxB). I need to
I have two textboxes which uses the same class (they both need to be
I have two textboxes with a integer value in each textbox. I need to
I am using c#.net I have two textboxes which if !empty need to be
I have two textboxes for entering the name and price of an item, a
I'm using the jQuery datepicker where I have two textboxes (start date / end
I have some code where I need two separate required field validators for one
I have two textboxes, and a button. When I press the button, I want
I need to populate the date time values in two textboxes at a same

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.