Should I use Page_Init or OnInit ?
November 1, 2006
I came across an interesting issue last friday.
There was an empty Page_Init method in some web control. I removed it, thinking that it would not do any harm.
Well, in fact, it was actually hidding the base class Page_Init method which used not to be executed. Of course, after my change, the base method was called and that caused a crash in the application
What I have learned from that:
When creating a base class that requires initialization, it’s better to use the OnInit method, rather that the Page_Init.
When using OnInit, the derived class will have to explicitly use the override keyword, which may help other developers avoiding this kind of issues.