AddHandler(PageCommandKey, value);
}
remove
{
Events.RemoveHandler(PageCommandKey, value);
}
}
228 CHAPTER 5 ?– SE RVER CONTROL EVENTS
We also add an OnPageCommand method to raise the event. This method uses the custom
PageCommandEventArgs class we defined earlier to invoke the PageCommandEventHandler delegate:
protected virtual void OnPageCommand(PageCommandEventArgs pce)
{
PageCommandEventHandler pageCommandEventDelegate =
(PageCommandEventHandler) Events[PageCommandEvent];
if (pageCommandEventDelegate != null)
{
pageCommandEventDelegate(this, pce);
}
}
OnPageCommand is the last bit of code required to raise events associated with the PageCommand
event type. The next task is to capture the bubbled Command events and turn them into
PageCommand events.
Capturing the Bubbles via OnBubbleEvent
The OnBubbleEvent method inherited from System.Web.UI.Control is the counterpart to the
RaiseBubbleEvent method used inside the SuperButton control. It allows a control to hook into
the stream of bubbled events from child controls and process them accordingly:
protected override bool OnBubbleEvent(object source, EventArgs e);
The method definition for OnBubbleEvent specifies the ubiquitous System.EventHandler
method signature, with one difference.
Pages:
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331