473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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

Jul 19 '05 #1
2 5532
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

<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #2
Hey, if you see this, drop me an email.
I think you will figure out how.
-Rz
I like your return address. LOL
"Ben" <mu**********@120spamsaday.con> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
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

<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
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


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
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...
0
by: canasdaq | last post by:
Can anyone please help me. I was looking at the article "http://www.eggheadcafe.com/articles/20030603.asp". I am new to .net and know nothing in c#. I want to write a menu in asp.net. Can anyone...
1
by: Stephen Adam | last post by:
Hi there, I've just started a c# project at work where I cannot use Visual Studio. I am trying to pass variables from one form to another. When I try to create an instance of the sending class...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
5
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access...
2
by: Dave | last post by:
Hi, this is a follow-up to an earlier question but I really haven't found a definitive answer in my search If I have a Base and Derived webform, I've found that the dervived Page_Load event...
1
by: harry potter | last post by:
Hi, Are there any reasons to use OnInit or Page_Init method to invoke some code when the Init event is triggered, if at all. Or are they both just the same? -S.
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, Is OnInit and Page_Init the same thing? thanks, rodchar
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.