更新时间:2023-01-06 22:26:15
Page_LoadComplete$c$c>是所有控件已经被加载后所引发的事件。
Page_LoadComplete
is the event that is raised after all controls have been loaded
记住初始化
事件首先由所有子控件触发,就在所有的控制已被初始化,初始化
页的事件引发的。在加载
事件工作周围的其他方法,页面首先提出了一个加载
事件,然后每个子控件提高自己的加载
事件。在结束了 LoadComplete
升高。 请注意,在创建控件时动态他们(黯然)没有严格按照这个办法在设计时,创建控件只有当这是真的。
Remember that the Init
event is first triggered by all child controls, and just when all controls have been initialized, the Init
event of the page is raised. The Load
event works the other way around, the page first raises the Load
event and then each child control raises its own Load
event. At the end the LoadComplete
is raised. Note that this is true only when the controls are created at design time, when the controls are created dynamically they (sadly) do not follow this approach strictly.
从MSDN:
如果在运行时动态创建的控件或声明中的数据绑定控件模板,他们的活动最初不与其他控件的页面上同步。例如,对于在运行时增加了一个控制,init和负载事件可能会在页面生命周期远远晚于控件相同的事件声明创建发生。因此,从它们被实例化时,动态添加管制和模板提高他们的事件一前一后,直到它们已经赶上到在此期间它被添加到控制集合的事件。
If controls are created dynamically at run time or declaratively within templates of data-bound controls, their events are initially not synchronized with those of other controls on the page. For example, for a control that is added at run time, the Init and Load events might occur much later in the page life cycle than the same events for controls created declaratively. Therefore, from the time that they are instantiated, dynamically added controls and controls in templates raise their events one after the other until they have caught up to the event during which it was added to the Controls collection.
请看下图:
(来源:http://msdn.microsoft.com/en-us/library/ms178472.aspx)
为了满足您的所有需求:
In order to fulfill all your requirements:
我需要一种方式来运行code所有的Page_Load事件后发射,但在此之前的任何回发事件(例如点击事件)已经解雇了:
i need a way to run code after all Page_Load events have fired, but before any postback events (e.g. Click events) have fired:
我觉得最简单的方法是在用户控件声明一个自定义事件,并启动它的控制已被加载后,再强制订阅该事件在你的ASPX
I think the easiest way is to declare a custom event in the User Control and fire it after the control has been loaded, then jus subscribe to that event in your ASPX
public event Action LoadCompleted = delegate { };
protected void Page_Load(object sender, EventArgs e)
{
this.LoadCompleted();
}
protected void Page_Load(object sender, EventArgs e)
{
this.myUserControl.LoadCompleted += () =>
{
// do somethign interesting
this.lblMessage.Text = DateTime.Now.ToString();
};
}