Clicking on UserControl background fires Validating event twice

G

Guest

I have a Form containing a Label (Label1), a TextBox (TextBox1), and a
UserControl itself containing a Label (Label2) and a TextBox (TextBox2).
There is an event handler for the Validating event of TextBox1, which checks
whether the TextBox contains a valid value and, if not, displays a message
box and sets the Cancel property of the CancelEventArgs to True.

If the user enters an invalid value in TextBox1 and then clicks on TextBox2,
the Validating event handler is executed, the message box is displayed, and
focus stays on TextBox1 as expected.

If the user enters an invalid value in TextBox1 and then clicks on the
background of the UserControl (anywhere in the UserControl but outside Label2
and TextBox2), the Validating event handler is executed twice, and therefore
the message box is displayed twice before focus is returned to TextBox1,
which does not seem normal to me.

Does anybody understand the reason for this behaviour and how I could
prevent the same message box being displayed twice to the user?

Thanks in advance.
 
J

Jeffrey Tan[MSFT]

Hi desiderius,

Thanks for your post.

Yes, I can reproduce this issue in VS.net2003 IDE.

With some search in our internal database, I found that this is a known
issue of .Net1.1, the problem lies in UserControl.WmSetFocus method, which
forgets to check ValidationCancelled property to determine if anoter
validating is needed.(These are all internal methods and behavior, you can
ignore this if you feel uncomfortable)

Regarding this issue, our product team has fixed UserControl.WmSetFocus
method bug in .Net2.0, so it should work well in .Net2.0 now. However, I
can not think of a perfect workaround for .Net1.1.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top