谁在第一页呼叫第一个OnLoad呼叫

时间:2011-07-23 09:31:04

标签: c# asp.net

asp.net 3.5 我一直坐在Reflector中找出 - 谁是First(!)调用OnLoad方法,为所有订阅者激活事件 我没找到它。

我不是在谈论AutoEvenntWireup情况(这里不相关),因为这个阶段发生得晚......

我正在谈论:谁先激活Control.OnLoad方法? 我想在反射器中看到它,可以找到激活!我只能找到方法签名

1 个答案:

答案 0 :(得分:2)

Page.ProcessRequestMain()来电Page.LoadRecursive(),后者又拨打Page.OnLoad()

相关代码(用ILSpy反汇编)是:

internal virtual void LoadRecursive()
{
    if (this._controlState < ControlState.Loaded) {
        if (this._adapter != null) {
            this._adapter.OnLoad(EventArgs.Empty);
        } else {
            this.OnLoad(EventArgs.Empty);  // ** Here. **
        }
    }
    if (this._occasionalFields != null
        && this._occasionalFields.Controls != null) {
        string collectionReadOnly
            = this._occasionalFields.Controls.SetCollectionReadOnly(
                "Parent_collections_readonly");
        int count = this._occasionalFields.Controls.Count;
        for (int i = 0; i < count; i++) {
            this._occasionalFields.Controls[i].LoadRecursive();
        }
        this._occasionalFields.Controls.SetCollectionReadOnly(
            collectionReadOnly);
    }
    if (this._controlState < ControlState.Loaded) {
        this._controlState = ControlState.Loaded;
    }
}