Santosh Kumar Singh
Asp.net Difference between Page_Load and Page_Init in C#, VB.Net

Page_Init Event

This event will raise whenever page initialized and its first step in page life cycle. In this event all the controls in the page have been initialized and any theme or skin properties will be applied. This Page_Init event can be used to read or initialize control properties.

Declaration of Page_init

Generally we will use page_init event like as shown below

protected void Page_Init(object sender, EventArgs e)
{
// Your Code Here
}

For example check this for page_init event change page themes dynamically in asp.net

Page_Load Event

This event occurs only after Page_Init event and this event also will raise for every postback operation and in this stage all control properties are loaded with information recovered from view state and control state.

Declaration of Page_Load Event

Generally we will use page_load event like as shown below

protected void Page_Load(object sender, EventArgs e)
{
// Your Code Here
}
If you want to check it in complete example you need to write the code in your aspx page like as shown below







In code behind you need to write the code like as shown below

C# Code

using System;
public partial class BindDropdowninGridview : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
Response.Write(“Init Event”);
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(“Page Load Event”);
}
}

VB.NET Code

Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Response.Write(“Init Event”)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Response.Write(“Page Load Event”)
End Sub
End Class

By Santosh Kumar Singh in ASP.NET on Oct 07 2019
  • Madhura Kesharwani
    Jul, 2021 6

    Page_Init - In page life cycle, this event fired when all the controls are initialized and at this stage initialize each control's properties.Page_Load - 1.In page life cycle , at this event all values are restored. 2.Most code checks the value of IsPostBack to avoid unnecessarily resetting state. 3.You may also call Validate and check the value of IsValid in this method. 4. You can also create dynamic controls in this method. the value assigned to each control is set.

    • 0
  • Rajendran S
    May, 2021 10

    The Page_Init event fires only the first time the page is loaded. When you postback to any page, the Page_Init event doesn't fire. The Page_Load event fires each time the page loads, postback or not. This event occurs only when all the objects on the page have been created and are available for use

    • 0
  • Sanjay Kumar
    Jan, 2021 16

    Page_init Page_init Event is First occur when a asp.net page is executed.This is where you perform any initialization steps that you need to set up or create instances of sever controls. You cant’s access controls in this event because there is no guarantee that they have been created yet. Controls are created during this, and you can control whether your attempt to use these objects will be denied by the server processing your request. The Page_Init event first only the first time the page is loaded. When you postback to any page, the Page_Init event doesn’t fire.The Page Load event fires each time the loads, postback or not. Page_Load This event occurs only when all the objects on the page have been created and are available for use.

    • 0
  • Nisha Regil
    Sep, 2020 8

    The Page_Init event fires only the first time the page is loaded. When you postback to any page, the Page_Init event doesn't fire. The Page_Load event fires each time the page loads, postback or not.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS