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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:12:08+00:00 2026-05-31T19:12:08+00:00

I open a form as a modal dialog using ShowDialog. This dialog in turn

  • 0

I open a form as a modal dialog using ShowDialog. This dialog in turn allows another form to be opened as a modal dialog again using ShowDialog.

When the innermost dialog is closed, this causes its parent dialog to close as well. Why does this occur and how can I prevent it?

I have created a hello world version of the problem to illustrate this.

Form 1:

Form 1

private void OpenForm2Button_Click(object sender, EventArgs e)
{
    Form2 testForm = new Form2();
    DialogResult dialogResult = new DialogResult();
    dialogResult = testForm.ShowDialog();
    MessageBox.Show("Form 2 returned: " + Convert.ToString(dialogResult));
}

Form 2:

Form 2

...
this.Form2OKButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Form2CancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
...
this.AcceptButton = this.Form2OKButton;
this.CancelButton = this.Form2CancelButton;
...
private void OpenForm3Button_Click(object sender, EventArgs e)
{
    Form3 testForm = new Form3();
    DialogResult dialogResult = new DialogResult();
    dialogResult = testForm.ShowDialog();
    MessageBox.Show("Form 3 returned: " + Convert.ToString(dialogResult));
}

Form 3:

Form 3

...
this.Form3OKButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Form3CancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
...
this.AcceptButton = this.Form3OKButton;
this.CancelButton = this.Form3CancelButton;

Steps to reproduce:

  • Click “Open Form 2”
  • Click “Open Form 3”
  • Click “Cancel”

Form 3 closes with DialogResult == Cancel as expected, but Form 2 also closes with DialogResult == Cancel (not expected).

  • 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-31T19:12:09+00:00Added an answer on May 31, 2026 at 7:12 pm

    EDIT :

    the problem is this one (file: Form2.Designer.cs):

    this.OpenForm3Button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    

    when you click the OpenForm3Button, after the end of the OpenForm3Button_Click event handler, the form.DialogResult is automatically set to Cancel and it is closed.

    Reset the DialogResult property of OpenForm3Button and it will work as expected 🙂

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

Sidebar

Related Questions

I'm using this simple modal dialog example here: http://jqueryui.com/demos/dialog/modal-form.html When the page loads, jQuery
I am using jQueryUI dialog to open a modal form on my site. The
A ComboBox within a Form (modal dialog) does not open when clicked, however an
I am using this function to close existing form and open a new form.
I am tryng to use this: http://jqueryui.com/demos/dialog/#modal-form I have: <script type=text/javascript> $(document).ready(function() { $(#dialog).dialog();
I am using Lightbox Gone Wild to display a modal dialog with a form
I have a form that can open a sub form (with ShowDialog ). I
I am using main form and child forms. If I open 2nd child form
I'm trying to display a modal form using jquery ui. I've adapted an example
I'm trying to do a confirm dialog using jquery, but the form doesn't get

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.