Override OnLoad() vs. Adding a Load_Handler(), what's the difference?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

For all the control event handling, one can either override the protected
methods:
OnLoad(EventArgs e),
OnInit(EventArgs e),
OnPreRender(EventArgs e) etc,

or add handler functions like
Load_Handler(object sender, EventArgs e),
Init_Handler(object sender, EventArgs e),
PreRender_Hanlder(object sender, EventArgs e)

and hook them to the Load, Init, PreRender events (e.g. this.Load += new
EventHandler(Load_Handler). What are the scenarios for using one vs. the
other?
 
you can only override once, but can wire up several event handlers.

override is usually used when you want to change the behavior of the method,
event handling is used when some code needs to be notified that the event
has happened (its responding to the event, not changing its meaning).

-- bruce (sqlwork.com)
 
Back
Top