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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:11:17+00:00 2026-05-24T18:11:17+00:00

I have created a dialog box in my WinForms application. This has many text

  • 0

I have created a dialog box in my WinForms application. This has many text boxes and ok/cancel buttons. When the user clicks ok, I only want the dialog box to close if all entries are valid. I can see how to do this with the “Validating” events for each control separately. That is fine. But these only seem to fire when a control loses focus. However, empty text boxes in my dialog are also invalid input which means the user may never have focused on that control. I would prefer to just validate all controls on clicking OK.

I can’t work out how to do this though. Overriding the onclick of the OK button doesn’t seem to have an option for stopping the window from closing. The Form IsClosing event does by setting Cancel = true. But this doesn’t seem to be able to distinguish between whether the OK or Cancel button is clicked. Obviously if the cancel button is clicked I don’t care about validation and want to allow the form to close regardless.

What is the best approach for doing this?]

Update:
I already had CausesValidation set to true on both my form and ok button but my validation event does not get fired when I click the ok button. I mention this as it was suggested as a solution below.

  • 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-05-24T18:11:19+00:00Added an answer on May 24, 2026 at 6:11 pm

    Please select the form > Set the property CausesValidation to true

    Select OK button and again set property CausesValidation to true

    and then it will take care of all the validations.

    Important points:
    1) You must mention e.Cancel=true in all the validating eventhandlers

    2) If your buttons are in panels then you must set panels (or any parent control’s) CausesValidation property to true

    Edit:

    3) Validate fires just before loss of focus. While pressing Enter will
    cause the default button to Click, it doesn’t move the focus to that
    button, hence no validation event will be fired if you have set forms AcceptButton Property to OK button

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

Sidebar

Related Questions

I have created a user login Dialog Box in MFC, which have two edit
I have a dialog box open when a user clicks on a url. In
I am using windows forms application using C#. I have created a dialog box
I have a dialog box, created with the code javascript and HTML generated below.
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
hello all I have a small dialog which I created dynamically, which has a
I created a dialog box like this: String response = JOptionPane.showInputDialog(null,message,title,JOptionPane.PLAIN_MESSAGE); I'd like to
Hi I have created a user message page with this plugin. The grid will
I have created a custom dialog box which requires 3 fields public class Test{
I have created an application in C# with visual studio. The application has a

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.