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 该方法被重写,则调用 override 方法而不是 Control.OnInit 方法。

重写 OnInit 以在 Initialize 控件生命周期阶段执行特定于目标的处理。 通常,这些是创建控件时执行的函数。

继承者说明

从 类继承 ControlAdapter 并且适配器重写 OnInit(EventArgs) 方法时,适配器必须调用相应的基类方法,后者又调用 OnInit(EventArgs) 方法。 OnInit(EventArgs)如果未调用 方法,Init则不会引发 事件。

适用于

另请参阅