private static void RegisterCssIncludes(string innerHtml, ClientDependencyLoader loader) { var tagPattern = string.Format(TagPattern, "link"); var typeAttributePattern = string.Format(AttributePattern, "type"); var srcAttributePattern = string.Format(AttributePattern, "href"); var count = 0; foreach (Match match in Regex.Matches(innerHtml, tagPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) { var typeMatch = Regex.Match(match.Value, typeAttributePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (typeMatch.Success && typeMatch.Groups["val"].Value == "text/css") { var srcMatch = Regex.Match(match.Value, srcAttributePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (srcMatch.Success) { loader.RegisterDependency(DefaultPriority + count, srcMatch.Groups["val"].Value, ClientDependencyType.Css); count++; } } } }
private void RegisterIncludes(IEnumerable<BasicFile> files, ClientDependencyLoader loader, ClientDependencyType dependencyType) { foreach (var file in files) { loader.RegisterDependency(file.Group, file.Priority, file.FilePath, "", dependencyType, file.HtmlAttributes, file.ForceProvider); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.CssClass = "xpath-templatable-list-wrapper"; this.EnsureChildControls(); if (!this.Page.IsPostBack) { this.selectedItemsHiddenField.Value = this.data.Value.ToString(); } this.PopulateSourceList(); // add custom css from options if (!string.IsNullOrWhiteSpace(this.options.CssFile)) { ClientDependencyLoader clientDependencyLoader = ClientDependencyLoader.GetInstance(new HttpContextWrapper(HttpContext.Current)); clientDependencyLoader.RegisterDependency(this.options.CssFile, ClientDependency.Core.ClientDependencyType.Css); } // add datatype css / js this.RegisterEmbeddedClientResource("uComponents.DataTypes.XPathTemplatableList.XPathTemplatableList.css", ClientDependencyType.Css); this.RegisterEmbeddedClientResource("uComponents.DataTypes.XPathTemplatableList.XPathTemplatableList.js", ClientDependencyType.Javascript); // if selecting a js file, it'll read in the contents of that file server side, and pass that string as a callback to the datatype init function string customCallbackScript = null; if (!string.IsNullOrWhiteSpace(this.options.ScriptFile)) { string scriptFile = HostingEnvironment.MapPath("~" + this.options.ScriptFile); if (scriptFile != null) { customCallbackScript = File.ReadAllText(scriptFile); } } if (string.IsNullOrWhiteSpace(customCallbackScript)) { customCallbackScript = "null"; // ensure a clean js method call } string startupScript = @" <script language='javascript' type='text/javascript'> $(document).ready(function () { XPathTemplatableList.init(jQuery('div#" + this.div.ClientID + "'), " + customCallbackScript + @"); }); </script>"; ScriptManager.RegisterStartupScript(this, typeof(XPathTemplatableListDataEditor), this.ClientID + "_init", startupScript, false); }