Prev | Current Page 277 | Next

Rob Cameron and Dale Michalk

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

The delegate associated with an event can have one or more client methods
in its invocation list that will be called when the object indicates that an event has occurred, as
is the case with a MulticastDelegate.
We can declare an event using the event keyword followed by a delegate type and the name of
the event. The following event declaration creates a Click event with public accessibility that
would be right at home on a Button control:
public event EventHandler Click;
The name of the event should be a verb signifying that some action has taken place. Init,
Click, Load, Unload, and TextChanged are all good examples of such verbs used in the ASP.NET
framework.
The event declaration causes the C# compiler to emit code that adds a private field to the
class named Click, along with add and remove methods for working with the events hooked in
from clients. The nice thing about the event declaration and the code it generates is that it
happens under the covers without your having to worry about it. Later on in this chapter, we
discuss how to optimize event registration with respect to storage for controls that publish a
large number of events, but only a small fraction of them are likely to be subscribed to for a
given control instance.


Pages:
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289