Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

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

Feb 21, 2015
Introduction:

Here I will explain difference between page_init and page_load in asp.net using c#, vb.net with example.

Description:


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 RSS subscribe by email Subscribe by Email

1 comments :

Vakeel Mansoori said...

nice

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.