Control.OnUnload Method
.NET Framework 3.0
Raises the Unload event.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
'Declaration Protected Friend Overridable Sub OnUnload ( _ e As EventArgs _ ) 'Usage Dim e As EventArgs Me.OnUnload(e)
protected void OnUnload ( EventArgs e )
protected internal function OnUnload ( e : EventArgs )
Not applicable.
Parameters
- e
An EventArgs object that contains event data.
The following example creates a text stream object, myFile, and uses it to print messages to a text file when defined Page and control lifecycle events occur during request processing. During the OnUnload method call, the string "Custom control was unloaded" is written to the file and the text stream object is closed.
' Create a StreamWriter to write data to a text file. Dim myFile As TextWriter = File.CreateText("c:\NewTextFile.txt") Sub Page_Load(sender As Object, e As EventArgs) ' Write status to file. myFile.WriteLine("Page has loaded.") End Sub Sub CustomControl_OnLoad(sender As Object, e As EventArgs) myFile.WriteLine("Custom control has loaded.") End Sub Sub CustomControl_OnUnload(sender As Object, e As EventArgs) ' Server controls final cleanup such as; ' closing files etc.goes here myFile.WriteLine("Custom control was unloaded.") ' Close the stream object. myFile.Close() End Sub
// Create a StreamWriter to write data to a text file.
TextWriter myFile = File.CreateText("c:\\NewTextFile.txt");
void Page_Load(Object sender,EventArgs e)
{
// Write status to file.
myFile.WriteLine("Page has loaded.");
} //Page_Load
void CustomControl_OnLoad(Object sender,EventArgs e)
{
myFile.WriteLine("Custom control has loaded.");
} //CustomControl_OnLoad
void CustomControl_OnUnload(Object sender,EventArgs e)
{
// Server controls final cleanup such as;
// closing files goes here
myFile.WriteLine("Custom control was unloaded.");
// Close the stream object.
myFile.Close();
} //CustomControl_OnUnload
Community Additions
ADD
Show: