Page_LoadComplete
is the event that is raised after all controls have been loaded
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.
From MSDN:
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.
Take a look:
(source: http://msdn.microsoft.com/en-us/library/ms178472.aspx)
Edit 1
In order to fulfill all your requirements:
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:
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
User Control
public event Action LoadCompleted = delegate { };
protected void Page_Load(object sender, EventArgs e)
{
this.LoadCompleted();
}
ASPX page
protected void Page_Load(object sender, EventArgs e)
{
this.myUserControl.LoadCompleted += () =>
{
// do somethign interesting
this.lblMessage.Text = DateTime.Now.ToString();
};
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…