Click here to Skip to main content
11,581,982 members (75,909 online)
Click here to Skip to main content

How to skip calling Page_Load event

, 13 Jun 2012 CPOL 9.6K 3
Rate this:
Please Sign up or sign in to vote.
Difference between Page_Load and OnLoad event

Introduction

In this article I am going to explain the difference between Page_Load event and OnLoad event. After you have understanding on this you will get the answer of the question "How to skip calling Page_Load" event.

Background 

OnLoad event is responsible to call Page_Load event of our page. The OnLoad function is a virtual function in the System.Web.UI.Page class so we need to override this function if we want to provide a different implementation of this function. So in page Life cycle, first OnLoad executes which in turn calls the Page_Load function. When we override the "OnLoad" function in our class, we need to call the base.OnLoad() function which in turn calls the Page_Load event. If we skip calling/writing base.OnLoad(), then our application simply won't call the Page_Load event.

Using the code 

Below is the code snippet which upon execution will skip the Page_Load event. 

using System.Web; 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblMessage.Text = "Hello World";            
    }

    protected override void  OnLoad(EventArgs e)
    {
        //  base.OnLoad(e);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Verma Neeru
Software Developer (Senior)
India India
I am a senior software engineer in Noida. Primarly worked in .NET,SilverLight, Prism, ASP.NET, C# etc.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
nazishrizvi11-Jun-13 17:44
membernazishrizvi11-Jun-13 17:44 
GeneralMy vote of 5 Pin
bhargavpp17-Sep-12 19:46
memberbhargavpp17-Sep-12 19:46 
QuestionAutoEventWireup="false" Pin
giammin13-Jun-12 6:21
membergiammin13-Jun-12 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 13 Jun 2012
Article Copyright 2012 by Verma Neeru
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid