• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Tabpage knowing when the Parent Form is closing?

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?
0
directxBOB
Asked:
directxBOB
1 Solution
 
alex_pavenCommented:
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

0
 
Anurag ThakurTechnical ManagerCommented:
lot of links for how to handle your requirement in web forms
http://www.eggheadcafe.com/community/aspnet/3/10030709/how-to-confirm-the-webfor.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now