Difference between page_load and onLoad

What is difference between page_load and onLoad functions in ASP.NET codebehind?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You should probably read the Page Lifecycle Overview for more info.

This little bit should help clear up the difference:

Note that when an event handler is
created using the Page_event syntax,
the base implementation is implicitly
called and therefore you do not need
to call it in your method. For
example, the base page class’s OnLoad
method is always called, whether you
create a Page_Load method or not.
However, if you override the page
OnLoad method with the override
keyword (Overrides in Visual Basic),
you must explicitly call the base
method. For example, if you override
the OnLoad method on the page, you
must call base.Load (MyBase.Load in
Visual Basic) in order for the base
implementation to be run.

and

Pages also support automatic event
wire-up, meaning that ASP.NET looks
for methods with particular names and
automatically runs those methods when
certain events are raised. If the
AutoEventWireup attribute of the @
Page directive is set to true, page
events are automatically bound to
methods that use the naming convention
of Page_event, such as Page_Load and
Page_Init.

The OnLoad is part of the page and is always called. You don’t need to have a Page_Load method which is just optional extension of the event.

Method 2

Load is the event and OnLoad is a method that raises that event when called
it’s just base class implementation that does it of course, and therefore
needs to be called from deriving classes so that events work)

Method 3

They handle the same event but Page_Load() works only when AutoEventWireup=”true”.

Method 4

OnLoad fires the Load event, which Page_Load is a default event handler.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x