why Page_Load and OnLoad in VS, to protect developers?

  • Thread starter Thread starter foldface
  • Start date Start date
F

foldface

Hi
I am aware of how Page_Load and OnLoad work. What I am curious about is
-why- there are 2 mechanisms for doing the same thing, in particular why
Visual Studio will generate code to implement the Page_Load functionality
and not OnLoad.
When should either be used?
My guess is that because OnLoad should call the base.OnLoad method its
slightly cleaner using the Page_Load mechanism but that sounds a bit
naff.

Any ideas?

Ta
F
 
Hi
I am aware of how Page_Load and OnLoad work. What I am curious about is
-why- there are 2 mechanisms for doing the same thing, in particular why
Visual Studio will generate code to implement the Page_Load functionality
and not OnLoad.
When should either be used?
My guess is that because OnLoad should call the base.OnLoad method its
slightly cleaner using the Page_Load mechanism but that sounds a bit
naff.

Page_Load is a handler for the Load event. OnLoad is a virtual method called
during the load phase. You should call base.OnLoad from within your OnLoad
override, to allow base class functionality to work.

In particular, Control.OnLoad raises the Load event which is processed by
Page_Load.

A given event can be handled by more than one handler. This handler can be
in another class. You can only override a method from within a derived
class.
 
Page_Load is a handler for the Load event, which is generated in OnLoad.
OnLoad is inherited from Control (Page is derived from TemplateControl,
which is derived from Control).

Unless you are creating custom Page classes, you will generally stick with
the Page_OnLoad event handler instead of driving down into the methods
below.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top