Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between page_load and onLoad

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

like image 678
Mayur Avatar asked Aug 12 '10 05:08

Mayur


People also ask

What is Page_Load?

Your web form has a method called Page_Load. This method is called each time your page is loaded. This includes: 1. The first time the page is loaded, e.g., when a user enters the url to it or clicks on a link to it.

What is OnLoad in asp net?

ASP.NET calls this method to raise the Load event. If you are developing a custom control, you can override this method in order to provide additional processing. If you override this method, call the base control's OnLoad method to notify subscribers to the event.

What is Page_Load C#?

Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc. protected void Page_Load(object sender, EventArgs e) { int x = 10; } write this and put a break-point on int x = 10; watch sender and e.

What is pageLoad function in Javascript?

pageLoad() is a function that pages with an ASP.NET ScriptManager (i.e. MicrosoftAjax. js) will automatically execute after ASP.NET AJAX's client-side library initializes and then again after every UpdatePanel refresh.


2 Answers

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.

like image 165
Kelsey Avatar answered Sep 24 '22 08:09

Kelsey


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)

like image 36
anishMarokey Avatar answered Sep 23 '22 08:09

anishMarokey