Ask a Question related to ASP.NET General, Design and Development.
-
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
Guest
-
page_init executing twice
I am experiencing a weird problem with some buttons on my webpage. The page_init is executing twice when a button is clicked. If I replace the... -
Init Handler Not Firing After Page_Init
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.... -
Online cannot come up oninit results
16:55:29 Rowid 0xd4e702 not found for delete in partnum d00054,3 treep 0000000223f4ffb0: 40e0f902 02000000 37d20000 1cfe46fc @.......... -
difference between constructor and Page_Init()
Hi, what is the difference between the page-constructor and Page_Init() ? when to put what code where ? thanks chris -
Page_Init() and Page_Load()
Hi, what is the purpose of having a Page_Init() AND a Page_Load() event handler 'cause both will always be executed on loading a page ? What... -
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
Guest
-
Ben #3
Re: Using inheritance for web pages - why have a Page_Init when you can override OnInit?
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
<DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:OhhgCzlRDHA.2152@TK2MSFTNGP12.phx.gbl...newsgroup.> 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 thepage>
> Each aspx page is a class which Inherits System.Web.UI.Page. Then, eachevents> 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> (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 Guest
-
Ben #4
Re: Using inheritance for web pages - why have a Page_Init when you can override OnInit?
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" <natty@dao2com.com> wrote in message
news:uK33iNrRDHA.2460@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 [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!
Ben Guest
-
Natty Gur #5
Re: Using inheritance for web pages - why have a Page_Init when you can override OnInit?
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 [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Natty Gur Guest
-
Re: Using inheritance for web pages - why have a Page_Init when you can override OnInit?
Hey, if you see this, drop me an email.
I think you will figure out how.
-Rz
I like your return address. LOL
"Ben" <mustbejoking@120spamsaday.con> wrote in message
news:uFbIw4mRDHA.1896@TK2MSFTNGP12.phx.gbl...the> 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
>
>
>
> <DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
> news:OhhgCzlRDHA.2152@TK2MSFTNGP12.phx.gbl...> newsgroup.> > 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> page> >
> > Each aspx page is a class which Inherits System.Web.UI.Page. Then, each> events> > 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> > (respectively). The programmer (you or me) is supposed to flesh out the
> > Pgae_Load and, if you are using the Visual Studio designer, not touchOnLoad> > 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>> > 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



Reply With Quote

