ControlAdapter.OnInit(EventArgs) Metoda

Definicja

Zastępuje metodę OnInit(EventArgs) skojarzonej kontrolki.

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)

Parametry

e
EventArgs

Element EventArgs zawierający dane zdarzenia.

Przykłady

Poniższy przykładowy kod pochodzi z niestandardowej karty sterującej ControlAdapter z klasy. Następnie zastępuje OnInit metodę, aby ustawić właściwość w skojarzonej kontrolce i wywołać metodę podstawową w celu ukończenia inicjowania kontrolki.

#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

Uwagi

Jeśli istnieje adapter dołączony do Control obiektu i OnInit metoda jest zastępowana, metoda zastąpienia jest wywoływana zamiast Control.OnInit metody .

Przesłoń OnInit , aby wykonać przetwarzanie specyficzne dla określonego obiektu docelowego na Initialize etapie cyklu życia kontroli. Zazwyczaj są to funkcje wykonywane podczas tworzenia kontrolki.

Uwagi dotyczące dziedziczenia

Gdy dziedziczysz z ControlAdapter klasy i adapter zastępuje OnInit(EventArgs) metodę, karta musi wywołać odpowiednią metodę klasy bazowej, która z kolei wywołuje metodę OnInit(EventArgs) . OnInit(EventArgs) Jeśli metoda nie zostanie wywołana, Init zdarzenie nie zostanie podniesione.

Dotyczy

Zobacz też