问题描述
所以,我绝对没有逻辑,我的code。
我有两种方法 Page_Init
&安培; 的Page_Load
这两种方法被调用每次我点击按钮的时间。
这是有道理的,要的Page_Load被调用。但是,为什么Page_Init被调用每一次?
保护无效Page_Init(对象发件人,EventArgs的发送)
{}保护无效的Page_Load(对象发件人,EventArgs的发送)
{}保护无效Button1_Click1(对象发件人,EventArgs的发送)
{
//这里做什么
}
我猜你不知道页面生命周期。
Page_Init总是会叫上创建页面,它是页面加载之前调用。
pre初始化被称为然后初始化被称为然后pre加载,然后加载,然后pre渲染,然后几乎每次回发发生渲染上。
如果你是不是活的服务器上,您可以做到这一点伎俩。添加
跟踪=真
在Page指令会告诉你完整的页面周期。
与此类似,
<%@页面语言=VBAutoEventWireup =false的codeFILE =Default.aspx.vb
继承=_默认跟踪=真正的%GT;
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
}
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
Trace ="true"
in Page directive that will show you complete page cycle.
Like this,
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" Trace="true"%>
这篇关于ASP.Net - 的Page_Load和Page_Init被调用每个按钮上点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!