Tabpage knowing when the Parent Form is closing?

Posted on 2009-04-30
Last Modified: 2012-05-06
I have a tabpage within a form that I need information to be saved before people can close out of it.

The problem I am having is that the while the user can fill out the form I cannot prevent them from hitting the X in the top right corner and losing the data they have saved.

So how would I capture his OnClose event from within a tabpage?
Question by:directxBOB
    LVL 6

    Accepted Solution

    Assuming this is a windows forms project, it's incorrect to say 'from within the tabPage' because it does not have it's own code; the code is contained in the parent form.
    To prevent/ask the user to save first, handle the FormClosing event of the form. Then you can do something like the code below, of course you can elaborate with a dialog asking the user to save, as is customary.

      void Form1_FormClosing(object sender, FormClosingEventArgs e)
        if (!saved) e.Cancel = true; //cancel closing

    Open in new window

    LVL 26

    Expert Comment

    by:Anurag Thakur
    lot of links for how to handle your requirement in web forms

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now