Introduction: 
Here I will explain difference between page_init and page_load in asp.net using c#, vb.net with example.
Description:
In
previous posts I explained difference between ref and out
parameters in c#, what is authorization in asp.net, difference between throw and throw ex
in asp.net,
difference between wcf and web
application,
difference between len and datalength
in sql server
and many articles relating to interview questions, asp.net, c#.net. Now I will explain difference
between page_init and page_load in asp.net with example.
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
| 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1"
  runat="server"> 
<title></title> 
</head> 
<body> 
<form id="form2"
  runat="server"> 
<div> 
</div> 
</form> 
</body> 
</html> | 
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 | 
| If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. | |||
|  Subscribe by RSS  Subscribe by Email | |||
 
1 comments :
nice
Note: Only a member of this blog may post a comment.