Hi to all. I do have a small doubt regarding ASP.NET Page Life Cycle events. When I gone through the coding of an application i came to see both overriding of OnInit() method and also Page_Init event in same Page. I thought both the approaches serves the same purpose and I have seen mostly the implementation of overriden OnInt() only but not both. Most of the articles in the web explains about the better approach in these two but no one explained what happens if we implement both in a Page. Also explain what is the difference between writing some code before calling base.OnInit(e) and after calling base.OnInit(e). What does this situation means. Can anyone please help me regarding this.
Thanks in Advance.
Jaganathan BantheswaranPosted Oct 28, 2013, 6:39 AM
Init is the event whereas OnInit is the method that raises the Init event.
Page_Init is the name of the eventhandler that is attached to Init event.
We will override the OnInit method to add some more functionality to the OnInit method.
If you want to do some setup on controls in the Page or Page itself before the controls are rendered, override the OnInit method.
when the base.OnInit(e); is occurred, Page_Init event will be raised. If you dont call the base.OnInit(), then actual implementation of the base class wont be run & you may be endup with issues.
For more info
http://msdn.microsoft.com/en-us/library/ms178472.ASPX
http://msdn.microsoft.com/en-IN/library/cd6at422%28v=vs.110%29.aspx