Hi Jeff,
Yes, only Asp.net System.Web.UI.Control class has Unload event. .Net
Winform controls do not have Unload event.
In .Net Winform, the Form class has the "Closing" event("FormClosing" event
in .Net2.0) which is fired when the form is in the process of closing. So,
a general solution for your task is using this.FindForm() method to get the
main form reference, which the UserControl resides in; then you may
register a handler for the form's Closing/FormClosing event; in the
handler, you may save the usercontrol data.
Another solution is placing the code in UserControl.Dispose() method.
Normally, this method will be called when the form is closing, however,
since I did not do the complete analysis of this method, I am not sure if
there is any situations that this method is not called immediately, so I
stilll recommend the first solution of registerring form's
Closing/FormClosing event in UserControl.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jeff Gaines - 29 Jan 2007 10:35 GMT
On 29/01/2007 in message <DmjGWt4QHHA.1176@TK2MSFTNGHUB02.phx.gbl>
>Yes, only Asp.net System.Web.UI.Control class has Unload event. .Net
>Winform controls do not have Unload event.
Oh dear, we're the poor relations again :-)
Many thanks for that input Jeffrey, it gives me a couple of options at
least!

Signature
Jeff Gaines
Jeffrey Tan[MSFT] - 29 Jan 2007 15:32 GMT
Hi Jeff ,
Thanks for the feedback.
Yes, since the Asp.net BCL and Winform BCL are developed by different
teams, they choose different event model for its control model. I think
this makes sense, because Asp.net implements its server-side model itself,
while Winform encapsulates Win32 GUI controls model, their control model
may not always be identical.
Although Microsoft designs them with similar Control names so that
developers can quickly be familiar with the control model when moving from
one to the other. However, this will also introduce some confusion to
developers when switching between Asp.net and Winform. The best solution is
always consulting the MSDN to know without a doubt. :-)
Anyway, if you still need further help or have any concern, please feel
free to feedback. Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Serge Baltic - 29 Jan 2007 12:51 GMT
Hello,
> In .Net Winform, the Form class has the "Closing" event("FormClosing"
> event in .Net2.0) which is fired when the form is in the process of
> closing. So, a general solution for your task is using this.FindForm()
> method to get the main form reference, which the UserControl resides
> in; then you may register a handler for the form's Closing/FormClosing
> event; in the handler, you may save the usercontrol data.
What happens to FindForm if the control has no parent form at all? Null reference,
I guess. I'd rather use a self-contained solution to the problem. For example,
the HandleDestroyed event on the control will fire when the control window
is being destroyed (WM_DESTROY message). If this is your own control, override
the OnHandleDestroyed method instead of sinking the event (don't forget to
call the base implementation).
In some scenarios, OnVisibleChanged method / VisibleChanged event may also
be useful, because it may trigger earlier than HandleDestroyed and closer
to the moment when the user thinks that “the control has been unloaded”.
(H) Serge