Nkkppp Page_Init事件发生两次,但消息仅打印一次...是吗? [英] Nkkppp Page_Init Event Occurs Twice but the message is printed only once ...Y?

查看:103
本文介绍了Nkkppp Page_Init事件发生两次,但消息仅打印一次...是吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中..

1)当我运行以下代码时,Page_init事件发生一次并显示消息.
2)当再次单击该按钮时,页面生命周期开始,因此该页面被初始化,但是Page_init事件中的消息未打印.... Y ??

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??

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/>";
}
}
}

推荐答案

好吧,我只能说您的项目有问题.它不会这样发生,您可以在此处查看有关它的详细信息:
ASP.NET应用程序和页面生命周期 [ ^ ]
MSDN:ASP.NET页面生命周期概述 [
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[^]


这篇关于Nkkppp Page_Init事件发生两次,但消息仅打印一次...是吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆