public void RegisterExtenderControl <TExtenderControl>(TExtenderControl extenderControl, Control targetControl)
            where TExtenderControl : Control, IExtenderControl
        {
            if (extenderControl == null)
            {
                throw new ArgumentNullException("extenderControl");
            }
            if (targetControl == null)
            {
                throw new ArgumentNullException("targetControl");
            }

            VerifyTargetControlType(extenderControl, targetControl);

            if (!_pagePreRenderRaised)
            {
                throw new InvalidOperationException(AtlasWeb.ScriptControlManager_RegisterExtenderControlTooEarly);
            }
            if (_scriptReferencesRegistered)
            {
                throw new InvalidOperationException(AtlasWeb.ScriptControlManager_RegisterExtenderControlTooLate);
            }

            // A single ExtenderControl may theoretically be registered multiple times
            List <Control> targetControls;

            if (!ExtenderControls.TryGetValue(extenderControl, out targetControls))
            {
                targetControls = new List <Control>();
                ExtenderControls[extenderControl] = targetControls;
            }
            targetControls.Add(targetControl);
        }
        public void RegisterScriptDescriptors(IExtenderControl extenderControl)
        {
            if (extenderControl == null)
            {
                throw new ArgumentNullException("extenderControl");
            }

            Control extenderControlAsControl = extenderControl as Control;

            if (extenderControlAsControl == null)
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.InvariantCulture,
                                        AtlasWeb.Common_ArgumentInvalidType,
                                        typeof(Control).FullName),
                          "extenderControl");
            }

            List <Control> targetControls;

            if (!ExtenderControls.TryGetValue(extenderControl, out targetControls))
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.InvariantCulture,
                                        AtlasWeb.ScriptControlManager_ExtenderControlNotRegistered,
                                        extenderControlAsControl.ID),
                          "extenderControl");
            }

            Debug.Assert(targetControls != null && targetControls.Count > 0);

            // A single ExtenderControl may theoretically be registered multiple times
            foreach (Control targetControl in targetControls)
            {
                // Only register ExtenderControl scripts if the target control is visible and in the control tree.
                // Else, we assume the target was not rendered.
                if (targetControl.Visible && InControlTree(targetControl))
                {
                    IEnumerable <ScriptDescriptor> scriptDescriptors = extenderControl.GetScriptDescriptors(targetControl);
                    RegisterScriptsForScriptDescriptors(scriptDescriptors, extenderControlAsControl);
                }
            }
        }