Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below code..

1) when i run the below code Page_init event occurs once and the message is printed.
2) when the button is clicked again the page life cycle starts so the page is iniatised but the message within Page_init event is not printed....Y??

C#
namespace eventdemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblmessage.Text += "Page load event handled. <br />";
if (Page.IsPostBack)
{
lblmessage.Text += "Page post back event handled.<br/>";
}
}
protected void Page_Init(object sender, EventArgs e)
{
lblmessage.Text += "Page initialization event handled.<br/>";
}
protected void Page_PreRender(object sender, EventArgs e)
{
lblmessage.Text += "Page prerender event handled. <br/>";
}
protected void btnclick_Click(object sender, EventArgs e)
{
lblmessage.Text += "Button click event handled. <br/>";
}
}
}
Posted
Updated 19-Jun-12 18:27pm
v4
Comments
willempipi 19-Jun-12 13:26pm    
Do you have another _Default class somewhere? Don't know why but that solved it for me last time.
Prathap Gangireddy 19-Jun-12 22:24pm    
Sandeep..i think i didnt put my question in the right way..i have done the required changes in my question..can u please explain??.
Ganesan Senthilvel 20-Jun-12 0:28am    
Code format.

1 solution

Well, all I can say is you have some issue in your project. It does not happen as such and you can see details about it here:
ASP.NET Application and Page Life Cycle[^]
MSDN: ASP.NET Page Life Cycle Overview[^]
 
Share this answer
 
Comments
Maciej Los 19-Jun-12 16:31pm    
Good point, my 5!
Sandeep Mewara 21-Jun-12 16:47pm    
Thanks! :)
VJ Reddy 20-Jun-12 22:35pm    
Good answer and references. 5!
Sandeep Mewara 21-Jun-12 16:47pm    
Thanks! :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900