似乎ASP.NET使用緩存作爲@Marc說。見內部TemplateControl.HookUpAutomaticHandlers
。
通過使用dotPeek該方法的一部分:
internal void HookUpAutomaticHandlers()
{
...
object obj = TemplateControl._eventListCache[(object) this.GetType()];
if (obj == null)
{
lock (TemplateControl._lockObject)
{
obj = TemplateControl._eventListCache[(object) this.GetType()];
if (obj == null)
{
IDictionary local_1_1 = (IDictionary) new ListDictionary();
this.GetDelegateInformation(local_1_1);
obj = local_1_1.Count != 0 ? (object) local_1_1 : TemplateControl._emptyEventSingleton;
TemplateControl._eventListCache[(object) this.GetType()] = obj;
}
}
}
...
私人GetDelegateInformation
方法負責對控制創建代表。 TemplateControl._eventListCache
是一個Hashtable
它保存每個模板控件的代表。
所以,回答你的問題:
他是否爲每個請求做呢?
答案是否定的。 ASP.NET一次填充這個Hashtable
,然後使用緩存的值。
有趣的問題;它不會被* required *這樣做,因爲這個策略可以被緩存(甚至可以通過元編程來編譯)。但是,我不知道它實際上*做了什麼。 –