473,378 Members | 1,317 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,378 software developers and data experts.

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

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


Nov 17 '05 #1
4 3080
Ben
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

"Natty Gur" <na***@dao2com.com> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

You can override Onload function but OnLoad() is call by the framework
every time the page is loaded. But before the Page_Load() method is
called in your code-behind page. This allows you to do some action
before Page_load runs and the programmer code in the page_load executes,
such as security checking.
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #2
Ben
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

"Natty Gur" <na***@dao2com.com> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

You can override Onload function but OnLoad() is call by the framework
every time the page is loaded. But before the Page_Load() method is
called in your code-behind page. This allows you to do some action
before Page_load runs and the programmer code in the page_load executes,
such as security checking.
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #3
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #5

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...
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.