Page.OnInit(EventArgs) Page.OnInit(EventArgs) Page.OnInit(EventArgs) Page.OnInit(EventArgs) Method

定義

引發 Init 事件,以初始化頁面。Raises the Init event to initialize the page.

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

參數

e
EventArgs EventArgs EventArgs EventArgs

包含事件資料的 EventArgsAn EventArgs that contains the event data.

備註

OnInit方法會執行初始設定和安裝所需的步驟來建立Page執行個體。The OnInit method performs the initialization and setup steps required to create a Page instance. 在這個階段中網頁的生命週期中,宣告的伺服器控制項在頁面上會初始化為其預設狀態;不過,每個控制項的檢視狀態尚未填入。In this stage of the page's life cycle, declared server controls on the page are initialized to their default state; however, the view state of each control is not yet populated. 頁面上的控制項無法存取其他伺服器控制項在頁面上的Page_Init階段中的,不論其他控制項是子系或父控制項。A control on the page cannot access other server controls on the page during the Page_Init phase, regardless of whether the other controls are child or parent controls. 其他伺服器控制項不保證會建立且可供存取。Other server controls are not guaranteed to be created and ready for access.

OnInit方法之後呼叫OnPreInit方法,以及之前OnInitComplete方法。The OnInit method is called after the OnPreInit method and before the OnInitComplete method.

引發事件會透過委派叫用此事件處理常式。Raising an event invokes the event handler through a delegate. 如需詳細資訊,請參閱 < 處理和引發事件For more information, see Handling and Raising Events.

OnInit 方法也允許衍生類別處理事件,而不用附加委派。The OnInit method also allows derived classes to handle the event without attaching a delegate. 這是在衍生類別中處理事件的慣用技巧。This is the preferred technique for handling the event in a derived class.

給繼承者的注意事項

當在衍生類別中覆寫 OnInit(EventArgs) 時,請確定呼叫基底類別的 OnInit(EventArgs) 方法,使已註冊的委派能接收到事件。When overriding OnInit(EventArgs) in a derived class, be sure to call the base class's OnInit(EventArgs) method so that registered delegates receive the event.

適用於