예제 #1
0
        private static void AddScriptReferenceForScriptControl(List <ScriptReferenceBase> scriptReferences,
                                                               IScriptControl scriptControl)
        {
            IEnumerable <ScriptReference> scriptControlReferences = scriptControl.GetScriptReferences();

            if (scriptControlReferences != null)
            {
                Control scriptControlAsControl = (Control)scriptControl;
                ClientUrlResolverWrapper urlResolverWrapper = null;
                foreach (ScriptReference scriptControlReference in scriptControlReferences)
                {
                    if (scriptControlReference != null)
                    {
                        if (urlResolverWrapper == null)
                        {
                            urlResolverWrapper = new ClientUrlResolverWrapper(scriptControlAsControl);
                        }
                        // set containing control on each script reference for client url resolution
                        scriptControlReference.ClientUrlResolver = urlResolverWrapper;
                        scriptControlReference.IsStaticReference = false;
                        scriptControlReference.ContainingControl = scriptControlAsControl;

                        // add to collection of all references
                        scriptReferences.Add(scriptControlReference);
                    }
                }
            }
        }
예제 #2
0
        public void RegisterScriptDescriptors(IScriptControl scriptControl)
        {
            if (scriptControl == null)
            {
                throw new ArgumentNullException("scriptControl");
            }

            Control scriptControlAsControl = scriptControl as Control;

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

            // Verify that ScriptControl was previously registered
            int timesRegistered;

            if (!ScriptControls.TryGetValue(scriptControl, out timesRegistered))
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.InvariantCulture,
                                        AtlasWeb.ScriptControlManager_ScriptControlNotRegistered,
                                        scriptControlAsControl.ID),
                          "scriptControl");
            }

            // A single ScriptControl may theoretically be registered multiple times
            for (int i = 0; i < timesRegistered; i++)
            {
                IEnumerable <ScriptDescriptor> scriptDescriptors = scriptControl.GetScriptDescriptors();
                RegisterScriptsForScriptDescriptors(scriptDescriptors, scriptControlAsControl);
            }
        }