コード例 #1
0
        /// <summary>
        /// Loads jQuery depending on configuration settings (CDN, WebResource or site url)
        /// and injects the full script link into the page.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="jQueryUrl">Optional url to jQuery as a virtual or absolute server path</param>
        public static void LoadjQuery(Control control, string jQueryUrl)
        {
            ClientScriptProxy p = ClientScriptProxy.Current;

            if (!string.IsNullOrEmpty(jQueryUrl))
            {
                p.RegisterClientScriptInclude(control, typeof(WebResources), jQueryUrl, ScriptRenderModes.HeaderTop);
            }
            else if (jQueryLoadMode == jQueryLoadModes.WebResource)
            {
                p.RegisterClientScriptResource(control, typeof(WebResources), WebResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);
            }
            else if (jQueryLoadMode == jQueryLoadModes.ContentDeliveryNetwork)
            {
                // Load from CDN Url specified
                p.RegisterClientScriptInclude(control, typeof(WebResources), jQueryCdnUrl, ScriptRenderModes.HeaderTop);

                // check if jquery loaded - if it didn't we're not online and use WebResource
                string scriptCheck =
                    @"if (typeof(jQuery) == 'undefined')  
        document.write(unescape(""%3Cscript src='{0}' type='text/javascript'%3E%3C/script%3E""));";

                jQueryUrl = p.GetClientScriptResourceUrl(control, typeof(WebResources),
                                                         WebResources.JQUERY_SCRIPT_RESOURCE);
                p.RegisterClientScriptBlock(control, typeof(WebResources),
                                            "jquery_register", string.Format(scriptCheck, jQueryUrl), true,
                                            ScriptRenderModes.HeaderTop);
            }

            return;
        }
コード例 #2
0
        /// <summary>
        /// Loads the appropriate jScript library out of the scripts directory and
        /// injects into a WebForms page.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="jQueryUiUrl">Optional url to jQuery as a virtual or absolute server path</param>
        public static void LoadjQueryUi(Control control, string jQueryUiUrl)
        {
            ClientScriptProxy p = ClientScriptProxy.Current;

            // jQuery UI isn't provided as a Web Resource so default to a fixed URL
            if (jQueryLoadMode == jQueryLoadModes.WebResource)
            {
                //throw new InvalidOperationException(Resources.WebResourceNotAvailableForJQueryUI);
                jQueryUiUrl = WebUtils.ResolveUrl(jQueryUiLocalFallbackUrl);
            }

            if (!string.IsNullOrEmpty(jQueryUiUrl))
            {
                p.RegisterClientScriptInclude(control, typeof(WebResources), jQueryUiUrl, ScriptRenderModes.Header);
            }
            else if (jQueryLoadMode == jQueryLoadModes.ContentDeliveryNetwork)
            {
                // Load from CDN Url specified
                p.RegisterClientScriptInclude(control, typeof(WebResources), jQueryUiCdnUrl, ScriptRenderModes.Header);

                // check if jquery loaded - if it didn't we're not online and use WebResource
                string scriptCheck =
                    @"if (typeof(jQuery.ui) == 'undefined')  
        document.write(unescape(""%3Cscript src='{0}' type='text/javascript'%3E%3C/script%3E""));";

                p.RegisterClientScriptBlock(control,
                                            typeof(WebResources), "jquery_ui",
                                            string.Format(scriptCheck, WebUtils.ResolveUrl(jQueryUiLocalFallbackUrl)),
                                            true, ScriptRenderModes.Header);
            }

            return;
        }
コード例 #3
0
        /// <summary>
        /// Explicitly forces the client script to be rendered into the page.
        /// This code is called automatically by the configured event handler that
        /// is hooked to Page_PreRenderComplete
        /// </summary>
        private void RenderClientScript()
        {
            ClientScriptProxy scriptProxy = ClientScriptProxy.Current;
            string            script      = ToString(false);

            // TODO: This has to be fixed for ww.jquery.js
            if (UpdateMode != AllowUpdateTypes.None)
            {
                ScriptLoader.LoadjQuery(Page);
                ScriptLoader.LoadwwjQuery(Page);

                scriptProxy.RegisterClientScriptBlock(Page, typeof(WebResources), "submitServerVars", STR_SUBMITSCRIPT, true);
                scriptProxy.RegisterHiddenField(Page, "__" + ClientObjectName, "");


                script += string.Format(@"$(document.forms['{1}']).submit(function() {{ __submitServerVars({0},'__{0}'); }});",
                                        ClientObjectName, Page.Form.ClientID, SubmitCounter++);
            }

            scriptProxy.RegisterClientScriptBlock(Page, typeof(WebResources),
                                                  "ClientObject_" + ClientObjectName, script,
                                                  true);
        }