ControlAdapter.OnInit(EventArgs) メソッド

定義

関連付けられたコントロールの OnInit(EventArgs) メソッドをオーバーライドします。

protected public:
 virtual void OnInit(EventArgs ^ e);
protected internal virtual void OnInit(EventArgs e);
abstract member OnInit : EventArgs -> unit
override this.OnInit : EventArgs -> unit
Protected Friend Overridable Sub OnInit (e As EventArgs)

パラメーター

e
EventArgs

イベント データを含む EventArgs

次のコード サンプルでは、 ControlAdapter クラスからカスタム コントロール アダプターを派生させます。 次に、 OnInit メソッドをオーバーライドして関連付けられたコントロールにプロパティを設定し、基本メソッドを呼び出してコントロールの初期化を完了します。

#using <System.Web.dll>
#using <System.dll>

using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::Adapters;

public ref class CustomControlAdapter: public ControlAdapter
{
   // Override the ControlAdapter default OnInit implementation.
protected:
   virtual void OnInit( EventArgs^ e ) override
   {
      // Make the control invisible.
      Control->Visible = false;
      
      // Call the base method, which calls OnInit of the control,
      // which raises the control Init event.
      ControlAdapter::OnInit( e );
   }
};
using System;
using System.Web.UI;
using System.Web.UI.Adapters;

public class CustomControlAdapter : ControlAdapter
{
    // Override the ControlAdapter default OnInit implementation.
    protected override void OnInit (EventArgs e)
    {
        // Make the control invisible.
        Control.Visible = false;

        // Call the base method, which calls OnInit of the control,
        // which raises the control Init event.
        base.OnInit(e);
    }
}
Imports System.Web.UI
Imports System.Web.UI.Adapters

Public Class CustomControlAdapter
    Inherits ControlAdapter

    ' Override the ControlAdapter default OnInit implementation.
    Protected Overrides Sub OnInit(ByVal e As EventArgs)

        ' Make the control invisible.
        Control.Visible = False

        ' Call the base method, which calls OnInit of the control, 
        ' which raises the control Init event.
        MyBase.OnInit(e)

    End Sub
End Class

注釈

Control オブジェクトに接続されているアダプターがあり、OnInit メソッドがオーバーライドされている場合は、Control.OnInit メソッドの代わりにオーバーライド メソッドが呼び出されます。

制御ライフサイクルのOnInitステージでターゲット固有の処理を実行するには、Initializeをオーバーライドします。 通常、これらはコントロールの作成時に実行される関数です。

注意 (継承者)

ControlAdapter クラスから継承し、アダプターがOnInit(EventArgs) メソッドをオーバーライドする場合、アダプターは対応する基底クラス メソッドを呼び出す必要があります。これにより、OnInit(EventArgs) メソッドが呼び出されます。 OnInit(EventArgs) メソッドが呼び出されない場合、Init イベントは発生しません。

適用対象

こちらもご覧ください