Control.LoadControlState メソッド
アセンブリ: System.Web (system.web.dll 内)



カスタム ASP.NET コントロールの LoadControlState メソッドをオーバーライドするコード例を次に示します。このメソッドは、呼び出されると、このコントロールに関してコントロールの状態が以前に保存されているかどうかを確認し、保存されている場合は、内部プロパティ currentIndex を保存値に設定します。
OnInit メソッドは、Page で 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Control.LoadControlState メソッドのページへのリンク