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 8119461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:48:40+00:00 2026-06-06T04:48:40+00:00

I am just adding validation into a new winform. I am using the validating

  • 0

I am just adding validation into a new winform. I am using the validating and validated events, in conjunction with an error provider control. Please see code below.

No problem with first validation (ie. if user enters more than 12 characters). Error is set in validating event, and error stays until user enters 12 or less characters. Validated event is then entered and error is reset to empty string.

However, there is a problem with the 2nd validation on same text box. The code checks for zero length in text box.. and sets error with provider. Watching in the debugger, this code is indeed invoked, and error is set ok. Then something weird happens, the validated event is (unexpectedly) fired, and the code there promptly resets the error.

Why is the validated event fired when there is already an error set ? This seems like a .NET bug. Can anyone suggest another way of doing this, or say what I am doing wrong ?

Thanks,

Bazza

Private Sub SampleCodeTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles SampleCodeTextBox.Validating
    If SampleCodeTextBox.Text.Length > 12 Then
        e.Cancel = True
        FormErrorProvider.SetError(SampleCodeTextBox, "Max of 12 characters for sample code")
    End If

    If SampleCodeTextBox.Text.Trim.Length = 0 Then
        FormErrorProvider.SetError(SampleCodeTextBox, "Must enter a sample code")
    End If
End Sub

Private Sub SampleCodeTextBox_Validated(sender As Object, e As System.EventArgs) Handles SampleCodeTextBox.Validated
    FormErrorProvider.SetError(SampleCodeTextBox, "")
End Sub
  • 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-06T04:48:41+00:00Added an answer on June 6, 2026 at 4:48 am

    You need to set the CancelEventArgs.Cancel property to True when your zero-length Text check fails in your Validating event handler.

    From the MSDN article on the Control.Validated Event:

    If the Cancel property of the CancelEventArgs is set to true in the
    Validating event delegate, all events that would usually occur after
    the Validating event are suppressed.

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

Sidebar

Related Questions

I am just getting into adding Facebook opengraph into my app. I want to
I just started adding JS-validation to a signup form and I want the username
Using jquery validation: http://docs.jquery.com/Plugins/Validation I am also validating each field on blur: //validate each
I'm using Jquery and html and I just ran into an issue with list
I am just adding a account header for my website, that just displays the
Are Java annotations used for adding functionality to Java code besides just adding documentation
I have a Hg repository with changeset 0 representing just adding .hgignore. Starting with
I have just tried adding a WebService (asmx based) from a WebForms project to
I just tryed the standard way for adding CToolbar to a dialog on the
Normally when adding sprites to a layer in cocos2d I'd just add a pointer

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.