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
Solved

How can I determine if a radio button is clicked during a MaskedTextBox validated event?

Posted on 2013-06-21
6
295 Views
Last Modified: 2013-07-22
I have two radio buttons, ID One and ID Two.  I have two MaskedTextBoxes, ID One and ID Two.  The user can choose to enter an ID for either one of the MaskedTextBoxes.  These are two different types of IDs.  Each can be used to enter a person's ID to pull a record.  Some users will want to use ID One type and some users will want to use ID Two type.  During the respective MaskedTextBox's Validated event, the app searches for the entered ID and, if valid, populates the other fields on the screen accordingly.  If a user selects ID One radio button, the form clears, the ID One Masked Text Box is enabled and becomes the active control; and, the ID Two MaskedTextBox is disabled.  If a user selects ID Two radio button, the form clears, and the reverse occurs.  Here's the problem:

When a radio button is selected (while active control is the enabled MaskedTextBox), the Validate event of the current active control fires.  At this point, I really don't want to validate the active MaskedTextBox, as I am just clearing and trying to reset the form and change to enable the other MaskedTextBox.  I tried to used the radiobutton's Checked property, but, at this point in the process, the status hasn't changed yet.  It does not change until some time after the Validated event is finished.

How do I control the Validated event to only execute code when the Validated event is NOT triggered by changing the radio button selection?
0
Comment
Question by:spazjr01
  • 4
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39266776
You can check the property Checked to see if it is checked or not. See the documentation [here]
0
 

Author Comment

by:spazjr01
ID: 39266788
As I stated in the original problem, this does not work.  Please see second paragraph of original problem.
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 39266891
What happens when you set the CausesValidation property on the radio button to false?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.causesvalidation(v=vs.100).aspx
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:spazjr01
ID: 39266928
Unfortunately, the CausesValidation approach does not work either.  Just tried it.  Though property is set to false, the validated event still fires.  I read the info in the link.  This is for validating a web page.  Unfortunately, I'm not working on a web app.  This is a windows stand alone console app.  So, this approach does not appear to be for other controls on the form of a windows app form.
0
 

Accepted Solution

by:
spazjr01 earned 0 total points
ID: 39334754
To solve this I removed the Validation event and added an OK button, which the user clicks when ready to submit the ID.  I moved all validation code to the OK click event in order to control when it validates.  So, I had to work around this issue, because I couldn't find a solution stop the validation.
0
 

Author Closing Comment

by:spazjr01
ID: 39345494
Nobody provided a working solution, so I came up with my own work around.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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