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

G

Guest

Sorry, I mixed up the code- reposting with correct example now :)

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 OnLoad(ByVal e As EventArgs)

'Put user code to initialize the page here

MyBase.OnLoad(e)

End Sub 'OnInit

End Class
 
B

Ben

Totally agree. So the VB.NET code generation does it as well as the C#.
I get rid of them and override the base classes method as I would in any
other class.
You don't see people adding a handler for OnPreRender, you override don't
you.
I think who ever was writing the code generator was just being silly.

Ben W

PS Remember to call the base though
 
G

Guest

Hey, if you see this, drop me an email.
I think you will figure out how.
-Rz
I like your return address. LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top