示例#1
0
        /// <summary>
        /// Loads a Javascript file reference onto the page
        /// to the file at the given url.
        ///
        /// The url may be:
        ///
        ///   1. An absolute url "http://" or "https://"
        ///   2. A tilde url "~/"
        ///   3. A url relative to the given page
        ///
        /// </summary>
        /// <param name="page">The page on which to load</param>
        /// <param name="url">The url of the file</param>
        public static void LoadFileReference(Page page, string url)
        {
            ClientScriptManager clientscriptmanager = page.ClientScript;
            Type type = page.GetType();

            if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url))
            {
                string pageTildePath =
                    FileTools.GetTildePath(page);

                string resolvedUrl =
                    FileTools.GetResolvedUrl(pageTildePath, url);

                StringBuilder builder = new StringBuilder();

                builder.Append(script_file_1);
                builder.Append(resolvedUrl);
                builder.Append(script_file_2);

                string contents = builder.ToString();

                clientscriptmanager.RegisterClientScriptBlock
                    (type, url, contents, false);
            }
        }
示例#2
0
        /// <summary>
        /// Loads a CSS file reference onto the page
        /// to the file at the given url
        /// with the given CSS media attribute.
        ///
        /// The url may be:
        ///
        ///   1. An absolute url "http://" or "https://"
        ///   2. A tilde url "~/"
        ///   3. A url relative to the given page
        ///
        /// The media parameter may be used to give
        /// the CCS media attribute.  The parameter
        /// is ignored if it is null or empty.
        /// </summary>
        /// <param name="page">The page on which to load</param>
        /// <param name="url">The url of the file</param>
        /// <param name="media">The CSS media attribute if any</param>
        public static void LoadFileReference(Page page, string url, string media)
        {
            ClientScriptManager clientscriptmanager = page.ClientScript;
            Type type = page.GetType();

            if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url))
            {
                string pageTildePath =
                    FileTools.GetTildePath(page);

                string resolvedUrl =
                    FileTools.GetResolvedUrl(pageTildePath, url);

                StringBuilder builder = new StringBuilder();

                builder.Append(open_css_link);
                builder.Append(resolvedUrl);

                if ((media != null) && (media.Length > 0))
                {
                    builder.Append(media_css);
                    builder.Append(media);
                }

                builder.Append(shut_css_link);

                string contents = builder.ToString();

                clientscriptmanager.RegisterClientScriptBlock
                    (type, url, contents, false);
            }
        }