次の方法で共有


Control.OnInit メソッド

Init イベントを発生させます。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Friend Overridable Sub OnInit ( _
    e As EventArgs _
)
'使用
Dim e As EventArgs

Me.OnInit(e)
protected internal virtual void OnInit (
    EventArgs e
)
protected public:
virtual void OnInit (
    EventArgs^ e
)
protected void OnInit (
    EventArgs e
)
protected internal function OnInit (
    e : EventArgs
)
適用できません。

パラメータ

  • e
    イベント データを格納している EventArgs オブジェクト。

解説

このメソッドによって通知されると、サーバー コントロールはインスタンスを作成し、設定するために必要な初期化の手順を実行する必要があります。サーバー コントロールの有効期間のこの段階では、コントロールのビューステートを設定する必要があります。さらに、このメソッドを呼び出しているときは、このサーバー コントロールが子か親かにかかわらず、これ以外の他のサーバー コントロールにはアクセスできません。他のサーバー コントロールは、作成されていなかったり、アクセスの準備ができていなかったりする場合があります。

使用例

' Override the OnInit method to write text to the 
' containing page if the _text property is null.
      <System.Security.Permissions.PermissionSetAttribute( _
    System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _       
Protected Overrides Sub OnInit(e As EventArgs)
   MyBase.OnInit(e)
   If _text Is Nothing Then
      _text = "Here is some default text."
   End If
End Sub 'OnInit
// Override the OnInit method to write text to the 
// containing page if the _text property is null.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override void OnInit(EventArgs e)
{
   base.OnInit(e);
   if ( _text == null)
        _text = "Here is some default text.";
}
// Override the OnInit method to write text to the 
// containing page if the _text property is null.
protected void OnInit(EventArgs e)
{
    super.OnInit(e);
    if (get_Text() == null) {
        set_Text("Here is some default text.");
    }
} //OnInit

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

Control クラス
Control メンバ
System.Web.UI 名前空間
Page

その他の技術情報

ASP.NET ページのライフ サイクルの概要