/// <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; }
/// <summary> /// Loads the ww.jquery.js library from Resources at the end of the Html Header (if available) /// </summary> /// <param name="control"></param> /// <param name="loadjQuery"></param> public static void LoadwwjQuery(Control control, bool loadjQuery = true) { // jQuery is also required if (loadjQuery) { LoadjQuery(control); } ClientScriptProxy p = ClientScriptProxy.Current; p.RegisterClientScriptResource(control, typeof(WebResources), WebResources.WWJQUERY_SCRIPT_RESOURCE, ScriptRenderModes.Header); }