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

Discussion in 'ASP .Net' started by Guest, Jul 9, 2003.

  1. Guest

    Guest 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
     
    Guest, Jul 9, 2003
    #1
    1. Advertising

  2. Guest

    Ben Guest

    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" <> wrote in message
    news:...
    > 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!
     
    Ben, Jul 12, 2003
    #2
    1. Advertising

  3. Guest

    Natty Gur Guest

    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!
     
    Natty Gur, Jul 13, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    3,141
    Guest
    Jul 16, 2003
  2. Sally
    Replies:
    1
    Views:
    494
    bruce barker
    Apr 15, 2004
  3. harry potter

    Should I use Page_Init or OnInit method.

    harry potter, Feb 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,519
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,257
    Smokey Grindel
    Dec 2, 2006
  5. =?Utf-8?B?cm9kY2hhcg==?=

    OnInit and Page_Init

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 29, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    845
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 30, 2007
Loading...

Share This Page