"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:e0**************@TK2MSFTNGP02.phx.gbl...
Hi,
"Mythran" <ki********@hotmail.comwrote in message
news:7B**********************************@microsof t.com...
>>I once read an article somewhere describing why we should not override the
OnXXX methods of classes when you want to extend the functionality of a
class. It stated that you should handle the event instead (inside the
derived class). Does anyone know of this article or an article that
discusses this or the opposite (should override OnXXX instead of handling
the event)?
I'm not sure of that, IMO there is a reason why the OnXXX are marked as
protected virtual and that's cause it's expected that you have the need to
extend them.
In MSDN you find:
The OnXXX method also allows derived classes to handle the event without
attaching a delegate. This is the preferred technique for handling the
event in a derived class.
Hmm, I understand this and I have always overrode the OnXXX methods instead
of handling the events. I know I read something somewhere that says you
should not do this (at least in WebControls???) and instead handle the
event....but I can't remember where or the exact instance on when you should
not use the OnXXX methods...if I find it, I'll post it.
Thanks Nicholas and Ignacio,
Mythran