Prev | Current Page 333 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


Figure 5-21. The control life cycle
In order to discuss the control life cycle, we use a control that overrides the methods
necessary to track the execution of each of the life cycle events as they occur. Listing 5-19
provides the class file for the Lifecycle control that handles this task. The implementation of
each overridden method is quite simple, with a call to the trace function notifying us that the
method is executing.
Listing 5-19. The Lifecycle Control Class File
using System;
using System.Web.UI;
using System.Collections.Specialized;
using System.Diagnostics;
namespace ControlsBook2Lib.Ch05
{
[ToolboxData("<{0}:lifecycle runat=server>")]
public class Lifecycle : Control, IPostBackEventHandler, IPostBackDataHandler
{
CHAPTER 5 ?–  SERVER CONTROL EVEN TS 241
// Init Event
protected override void OnInit(System.EventArgs e)
{
Trace("Lifecycle: Init Event.");
base.OnInit(e);
}
protected override void TrackViewState()
{
Trace("Lifecycle: Track ViewState.");
base.TrackViewState();
}
// Load ViewState Event
protected override void LoadViewState(object savedState)
{
Trace("Lifecycle: Load ViewState Event.");
base.LoadViewState(savedState);
}
protected override void LoadControlState(object savedState)
{
Trace("Lifecycle: Load ControlState Event.


Pages:
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345