In my code behind I wire up my events like so:
protected override void OnInit(EventArgs e) { base.OnInit(e); btnUpdateUser.Click += btnUpateUserClick; }
I’ve done it this way because that’s what I’ve seen in examples.
- Does the base.OnInit() method need to be called?
- Will it be implicitly be called?
- Is it better to call it at the beginning of the method or at the end?
- What would be an example where confusion over the base method can get you in trouble?
I should clarify:
The guidelines recommend that firing an event should involve calling a virtual ‘OnEventName‘ method, but they also say that if a derived class overrides that method and forgets to call the base method, the event should still fire.
See the ‘Important Note’ about halfway down this page: