What effect does MyBase.OnInit (e) not use when overriding it in a derived class?

I inherit a TextBox and override OnInit.

Protected Overrides Sub OnInit(e As EventArgs)

MyBase.OnInit(e) 

' I'm adding a dynamic control to go along with my textbox here...
Controls.Add(Something)

End Sub

I have MyBase.OnInit (e) in the above example, but I have been using my control for some time without it since I forgot to put it there. This is what I usually do out of habit, so I never thought about my goal:

When overriding OnInit in a derived class, be sure to call the class OnInit base so that registered delegates receive the event.

I am a little confused that this is not clear to me, but my control works fine, so I just hoped that someone could give an example of what could create a problem.

+4
source share
1

TextBox, Control, , OnInit:

protected internal virtual void OnInit(EventArgs e) {
    if(HasEvents()) {
        EventHandler handler = _events[EventInit] as EventHandler;
        if(handler != null) {
            handler(this, e);
        }
    }
}

, base.OnInit, , .

+4

All Articles