Control.LoadControlState Method
Assembly: System.Web (in system.web.dll)
Override this method when you need to specify how a custom server control restores its control state. For more information, see ASP.NET State Management.
The following code example overrides the LoadControlState method in a custom ASP.NET control. When this method is invoked, it determines whether control state was previously saved for the control and, if so, sets the internal property currentIndex to the saved value.
The OnInit method is overridden to call the RegisterRequiresControlState method on the Page to indicate that the custom control uses control state.
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
Control ClassControl Members
System.Web.UI Namespace
SaveControlState
ViewState
SaveViewState