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 / October 2004

Tip: Looking for answers? Try searching our database.

Validating on the OK click

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
carlor - 13 Oct 2004 15:55 GMT
Hi there,

I have a form that requires the user to enter two dates where the first must
be before the second. I only want to validate the dates when the user clicks
the OK button.

I've tried using the validating events but the best I was able to accomplish
was to have the validating event fire for the group box that contains the
date entry controls. The problem that occurs then is that the event fires
because the user clicked on the OK button. That seems to cancel out the OK
click and you have to click OK again.

I then tried to do the validation during the OK button clicked event.
Unfortunately, I can't figure out how to cancel the click event if there is a
problem with the date. I'm able to pop up an error message, but then it just
continues to close down the form and return to the calling form. Is there a
clean way to do it?

Thanks,

Carlo.
Sijin Joseph - 14 Oct 2004 05:00 GMT
are you setting CancelEventArgs.Cancel = true in case validation is failing.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hi there,
>
[quoted text clipped - 17 lines]
>
> Carlo.
carlor - 14 Oct 2004 14:15 GMT
Yes, I was setting it to true.

Carlo.

> are you setting CancelEventArgs.Cancel = true in case validation is failing.
>
[quoted text clipped - 23 lines]
> >
> > Carlo.
Claes Bergefall - 14 Oct 2004 08:32 GMT
Don't set the AcceptButton property on your form
In your click event handler call Close if everything is valid

   /claes

> Hi there,
>
[quoted text clipped - 17 lines]
>
> Carlo.

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.