/// <summary>
        /// Register's the Css references for this control
        /// </summary>
        /// <param name="control"></param>
        public static void RegisterCssReferences(Control control)
        {
            // Add the link to the page header instead of inside the body which is not xhtml compliant
            HtmlHead header = control.Page.Header;

            foreach (string styleSheet in ScriptObjectBuilder.GetCssReferences(control))
            {
                if (null == header)
                {
                    // It would be nice to add the required header here, but it's too late in the page
                    // lifecycle to be modifying the Page.Controls collection - throw an informative
                    // exception instead and let the page author make the simple change.
                    throw new NotSupportedException("This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat=\"server\" />.");
                }

                bool addIt = true;  // looking for this stylesheet already in the header
                foreach (Control c in header.Controls)
                {
                    HtmlLink l = c as HtmlLink;
                    if (null != l && styleSheet.Equals(l.Href, StringComparison.OrdinalIgnoreCase))
                    {
                        addIt = false;
                        break;
                    }
                }

                if (addIt)
                {
                    HtmlLink link = new HtmlLink();
                    link.Href = styleSheet;
                    link.Attributes.Add("type", "text/css");
                    link.Attributes.Add("rel", "stylesheet");
                    header.Controls.Add(link);

                    // ASP.NET AJAX doesn't currently send a new head element down during an async postback,
                    // so we do the same thing on the client by registering the appropriate script for after
                    // the update. A HiddenField is used to prevent multiple registrations.
                    ScriptManager scriptManager = ScriptManager.GetCurrent(control.Page);
                    if (null == scriptManager)
                    {
                        throw new InvalidOperationException(Resources.E_NoScriptManager);
                    }
                    if (scriptManager.IsInAsyncPostBack &&
                        (null == control.Page.Request.Form["__AjaxControlToolkitCalendarCssLoaded"]))
                    {
                        ScriptManager.RegisterClientScriptBlock(control, control.GetType(), "RegisterCssReferences",
                                                                "var head = document.getElementsByTagName('HEAD')[0];" +
                                                                "if (head) {" +
                                                                "var linkElement = document.createElement('link');" +
                                                                "linkElement.type = 'text/css';" +
                                                                "linkElement.rel = 'stylesheet';" +
                                                                "linkElement.href = '" + styleSheet + "';" +
                                                                "head.appendChild(linkElement);" +
                                                                "}"
                                                                , true);
                        ScriptManager.RegisterHiddenField(control, "__AjaxControlToolkitCalendarCssLoaded", "");
                    }
                }
            }
        }
Exemple #2
0
 // Token: 0x060000E5 RID: 229 RVA: 0x0000392C File Offset: 0x00001B2C
 public static void RegisterCssReferences(Control control)
 {
     foreach (string href in ScriptObjectBuilder.GetCssReferences(control))
     {
         HtmlLink htmlLink = new HtmlLink();
         htmlLink.Href = href;
         htmlLink.Attributes.Add("type", "text/css");
         htmlLink.Attributes.Add("rel", "stylesheet");
         control.Page.Header.Controls.Add(htmlLink);
     }
 }
Exemple #3
0
 // Token: 0x060000E4 RID: 228 RVA: 0x00003917 File Offset: 0x00001B17
 public static IEnumerable <string> GetCssReferences(Control control)
 {
     return(ScriptObjectBuilder.GetCssReferences(control, control.GetType(), new Stack <Type>()));
 }
Exemple #4
0
        // Token: 0x060000E9 RID: 233 RVA: 0x00003EC8 File Offset: 0x000020C8
        private static IEnumerable <string> GetCssReferences(Control control, Type type, Stack <Type> typeReferenceStack)
        {
            if (typeReferenceStack.Contains(type))
            {
                throw new InvalidOperationException("Circular reference detected.");
            }
            IList <string> list;

            if (ScriptObjectBuilder.cssCache.TryGetValue(type, out list))
            {
                return(list);
            }
            typeReferenceStack.Push(type);
            IEnumerable <string> result;

            try
            {
                lock (ScriptObjectBuilder.sync)
                {
                    if (ScriptObjectBuilder.cssCache.TryGetValue(type, out list))
                    {
                        result = list;
                    }
                    else
                    {
                        List <string> list2 = new List <string>();
                        List <RequiredScriptAttribute> list3 = new List <RequiredScriptAttribute>();
                        foreach (RequiredScriptAttribute item in type.GetCustomAttributes(typeof(RequiredScriptAttribute), true))
                        {
                            list3.Add(item);
                        }
                        list3.Sort((RequiredScriptAttribute left, RequiredScriptAttribute right) => left.LoadOrder.CompareTo(right.LoadOrder));
                        foreach (RequiredScriptAttribute requiredScriptAttribute in list3)
                        {
                            if (requiredScriptAttribute.ExtenderType != null)
                            {
                                list2.AddRange(ScriptObjectBuilder.GetCssReferences(control, requiredScriptAttribute.ExtenderType, typeReferenceStack));
                            }
                        }
                        List <ScriptObjectBuilder.ResourceEntry> list4 = new List <ScriptObjectBuilder.ResourceEntry>();
                        int  num   = 0;
                        Type type2 = type;
                        while (type2 != null && type2 != typeof(object))
                        {
                            object[] customAttributes2 = Attribute.GetCustomAttributes(type2, typeof(ClientCssResourceAttribute), false);
                            num -= customAttributes2.Length;
                            foreach (ClientCssResourceAttribute clientCssResourceAttribute in customAttributes2)
                            {
                                list4.Add(new ScriptObjectBuilder.ResourceEntry(clientCssResourceAttribute.ResourcePath, type2, num + clientCssResourceAttribute.LoadOrder));
                            }
                            type2 = type2.BaseType;
                        }
                        list4.Sort((ScriptObjectBuilder.ResourceEntry l, ScriptObjectBuilder.ResourceEntry r) => l.Order.CompareTo(r.Order));
                        foreach (ScriptObjectBuilder.ResourceEntry resourceEntry in list4)
                        {
                            list2.Add(control.Page.ClientScript.GetWebResourceUrl(resourceEntry.ComponentType, resourceEntry.ResourcePath));
                        }
                        Dictionary <string, object> dictionary = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);
                        List <string> list5 = new List <string>();
                        foreach (string text in list2)
                        {
                            if (!dictionary.ContainsKey(text))
                            {
                                dictionary.Add(text, null);
                                list5.Add(text);
                            }
                        }
                        list = new ReadOnlyCollection <string>(list5);
                        ScriptObjectBuilder.cssCache.Add(type, list);
                        result = list;
                    }
                }
            }
            finally
            {
                typeReferenceStack.Pop();
            }
            return(result);
        }