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

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

  2. Guest

    Ben Guest

    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



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

  3. Guest

    Guest Guest

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


    "Ben" <> wrote in message
    news:...
    > 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
    >
    >
    >
    > <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >

    >
    >
     
    Guest, Jul 16, 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:
    556
    Natty Gur
    Jul 13, 2003
  2. Sally
    Replies:
    1
    Views:
    479
    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,488
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,974
    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:
    832
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 30, 2007
Loading...

Share This Page