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.

備註

方法會執行Page建立實例所需的初始化和設定步驟。 OnInitThe 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.

方法會在方法OnPreInit之後和OnInitComplete方法之前呼叫。 OnInitThe 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.

適用於