次の方法で共有


Control.OnUnload メソッド

Unload イベントを発生させます。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Friend Overridable Sub OnUnload ( _
    e As EventArgs _
)
'使用
Dim e As EventArgs

Me.OnUnload(e)
protected internal virtual void OnUnload (
    EventArgs e
)
protected public:
virtual void OnUnload (
    EventArgs^ e
)
protected void OnUnload (
    EventArgs e
)
protected internal function OnUnload (
    e : EventArgs
)
適用できません。

パラメータ

  • e
    イベント データを格納している EventArgs オブジェクト。

解説

サーバー コントロールは、有効期間のこの段階で、ファイルのクローズ、データベース接続の終了、オブジェクトの破棄など、任意の最終的なクリーンアップを実行する必要があります。

使用例

テキスト ストリーム オブジェクト myFile を作成し、要求処理中に定義済み Page とコントロールの有効期間イベントが発生したときに、このオブジェクトを使用してテキスト ファイルにメッセージを書き込む例を次に示します。OnUnload メソッドを呼び出し中、"Custom control was unloaded" という文字列がファイルに書き込まれ、テキスト ストリーム オブジェクトは終了します。

   ' 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.");
}
void CustomControl_OnLoad(object sender,EventArgs e)
{
   myFile.WriteLine("Custom control has loaded.");
}

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();
}
// 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

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

Control クラス
Control メンバ
System.Web.UI 名前空間
Unload

その他の技術情報

ASP.NET ページのライフ サイクルの概要