+ // This hashtable cashes methods and events found in user code
+ const string eventMethodCacheKey = "eventMethodCacheKey";
+ static Hashtable EventMethodCache
+ {
+ get { return (Hashtable) AppDomain.CurrentDomain.GetData (eventMethodCacheKey); }
+ set { AppDomain.CurrentDomain.SetData (eventMethodCacheKey, value); }
+ }
+
+ internal void WireupAutomaticEvents ()
+ {
+ Type cacheKey = this.GetType ();
+ Hashtable eventMethodCache = EventMethodCache;
+ ArrayList eventMethodList = eventMethodCache == null ? null : (ArrayList) eventMethodCache [cacheKey];
+
+ if (eventMethodList == null) {
+ eventMethodList = new ArrayList ();
+
+ if (!SupportAutoEvents || !AutoEventWireup)
+ return;
+
+ Type thisType = typeof (TemplateControl);
+ Type voidType = typeof (void);
+ Type [] DefaultParams = new Type [] {
+ typeof (object),
+ typeof (EventArgs) };
+
+ LifeCycleEvent[] _pageEvents = new LifeCycleEvent[] {
+ LifeCycleEvent.PreInit,
+ LifeCycleEvent.PreLoad,
+ LifeCycleEvent.LoadComplete,
+ LifeCycleEvent.PreRenderComplete,
+ LifeCycleEvent.SaveStateComplete,
+ LifeCycleEvent.InitComplete
+ };
+ List<LifeCycleEvent> pageEvents = new List<LifeCycleEvent>(_pageEvents);
+
+ bool isPage = Page.GetType().IsAssignableFrom(GetType());
+
+ for (int i = 0; i < methodNames.Length; i++) {
+
+ // Don't look for page-only events in non-page controls.
+ if (!isPage && pageEvents.Contains((LifeCycleEvent)i))
+ continue;
+
+ string methodName = methodNames [i];
+ MethodInfo method;
+ bool noParams = false;
+ Type type = GetType ();
+ do {
+ method = type.GetMethod (methodName, bflags, null, DefaultParams, null);
+ if (method != null) {
+ break;
+ }
+
+ type = type.BaseType;
+ }
+ while (type != thisType);
+
+ if (method == null) {
+ type = GetType ();
+ do {
+ method = type.GetMethod (methodName, bflags, null, Type.EmptyTypes, null);
+ if (method != null) {
+ noParams = true;
+ break;
+ }
+
+ type = type.BaseType;
+ }
+ while (type != thisType);
+
+ if (method == null)
+ continue;
+ }
+ if (method.ReturnType != voidType)