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

  • Home
  • SEARCH
  • 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 3221432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:52:31+00:00 2026-05-17T15:52:31+00:00

I have a button click event handler with the following pseudo code: private void

  • 0

I have a button click event handler with the following pseudo code:

private void btnSave_Click(object sender, EventArgs e)
{
  if(txt.Text.length == 0)
     this.Close();
  else
     // Do something else

  // Some other code...
}

This is just some simple code, but the point is, when the text length equals zero, I want to close the form. But instead of closing the form the code executes the part // Some other code. After the click event handler is completely executed, then the form is closed.

I know, when I place return right after this.Close() the form will close, but I’d like to know WHY the form isn’t direclty closed when you call this.Close(). Why is the rest of the event handler executed?

  • 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-17T15:52:32+00:00Added an answer on May 17, 2026 at 3:52 pm

    The rest of the event handler is executed because you did not leave the method. It is as simple as that.

    Calling this.Close() does not immediately “delete” the form (and the current event handler). The form will be collected later on by the garbage collector if there are no more references to the form.

    this.Close() is nothing than a regular method call, and unless the method throws an exception you will stay in the context of your current method.

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

Sidebar

Related Questions

I have one link button with a click event. When Clicked I want to
I am following this thread to disable/ enable the click on a button, Best
I have the following ControlTemplate : <ControlTemplate> <Grid VerticalAlignment=Stretch HorizontalAlignment=Left Width=400> <Grid.ColumnDefinitions> <ColumnDefinition Width=18
I am trying to figure out how to accomplish the following: Handle client-side click
I have form which is opened using ShowDialog Method. In this form i have
I have a bunch of textboxes on a XAML page that I wanted the
I have a TabControl and each Tab can contain the same UI but with
I'm using the Plupload file uploader within a form. I want to customize it
I am having a lot of trouble with a seemingly simple thing. In an

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.