Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Clicking on UserControl background fires Validating event twice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Desiderius - 09 Feb 2006 10:07 GMT
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.
"Jeffrey Tan[MSFT]" - 10 Feb 2006 06:16 GMT
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
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.