ASP.Net - 每次单击按钮时都会调用 Page_Load 和 Page_Init?
所以我的代码中完全没有逻辑。 我有两种方法 Page_Init
& Page_Load
每次单击按钮时都会调用这两个方法。 调用 Page_load 是有意义的。但是为什么每次都会调用Page_Init呢?
protected void Page_Init(Object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
// Do something here
}
So I have absolutely no logic in my code.
I have the two methods Page_Init
& Page_Load
Both methods get called every time I click the button.
It makes sense for Page_load to get called. But why does Page_Init get called every time?
protected void Page_Init(Object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
// Do something here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你不知道页面生命周期。
Page_Init 将始终在页面创建时被调用,并且在页面加载之前被调用。
几乎每次发生回发时,都会调用 Pre Init,然后调用 Init,然后调用 Pre Load,然后调用 Load,然后调用 Pre Render,然后调用 Render。
如果您不在实时服务器上,您可以执行此技巧。添加
页面指令,将显示完整的页面周期。
像这样,
I guess you are unaware of Page Life Cycle.
Page_Init will always be called on page creation and it is called before Page Load.
Pre Init is called then Init is called and then Pre Load and then Load and then Pre Render and then Render on almost every time postback happens.
You can do this trick if you are not on live server. Add
in Page directive that will show you complete page cycle.
Like this,