Page.RegisterRequiresControlState メソッド
アセンブリ: System.Web (system.web.dll 内)
構文
例外
解説
コントロールの状態を使用するカスタム サーバー コントロールは、要求のたびに RegisterRequiresControlState メソッドを呼び出す必要があります。これは、コントロールの状態についての登録が、ポストバック イベントの要求間で失われるためです。Init イベントで登録することをお勧めします。
RegisterRequiresControlState メソッドを呼び出すカスタム サーバー コントロールを次のコード例に示します。
Class Sample Inherits Control Dim currentIndex As Integer Overloads Sub OnInit(ByVal e As EventArgs) Page.RegisterRequiresControlState(Me) currentIndex = 0 MyBase.OnInit(e) End Sub Overloads Function SaveControlState() As Object If currentIndex <> 0 Then Return CType(currentIndex, Object) Else Return Nothing End If End Function Overloads Sub LoadControlState(ByVal state As Object) If (state <> Nothing) Then currentIndex = CType(state, Integer) End If End Sub End Class
public class Sample : Control { private int currentIndex = 0; protected override void OnInit(EventArgs e) { Page.RegisterRequiresControlState(this); base.OnInit(e); } protected override object SaveControlState() { return currentIndex != 0 ? (object)currentIndex : null; } protected override void LoadControlState(object state) { if (state != null) { currentIndex = (int)state; } } }
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Page.RegisterRequiresControlState メソッドのページへのリンク