Using inheritance for web pages - why have a Page_Init when you can override OnInit?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to better understand the use of inheritance vs. the
implementation of a handler. I wanted to ask this question to the newsgroup.

Each aspx page is a class which Inherits System.Web.UI.Page.
Then, each page has it's own implementation of Private Sub Page_Load and
Private Sub Page_Init to handle the Handles MyBase.Load and Handles
MyBase.Init events (respectively). The programmer (you or me) is supposed to
flesh out the Pgae_Load and, if you are using the Visual Studio designer,
not touch the Page_Init event handlers.

Instead of this, why don't these page classes, which are subclasses of
System.Web.UI.Page just overload the superclasses of the OnInit and OnLoad
classes? That would seem to make more sense from a class hierarchy
standpoint. Each page class, for example

'Instead of this:

Public Class WebForm1

Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

End Sub

End Class

'Do this:

Public Class WebForm1

Inherits System.Web.UI.Page

Protected Overrides Sub OnInit(ByVal e As EventArgs)

'Put user code to initialize the page here

MyBase.OnLoad(e)

End Sub 'OnInit

End Class
 
Disagree,

As the author of the class you should just sequence the code correctly on
the overridden OnLoad method!

It is actually going against MSs own guidelines to attach an event handler
for the same class that is raising the event.

Ben
 
but, he is the user...

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
Back
Top