protected override void OnInit(EventArgs e) { StyleSheetManager.RegisterControl(this); this.scriptNameDefaultValue = this.ScriptName; this.scriptPathDefaultValue = this.ScriptPath; base.OnInit(e); }
protected override void Render(HtmlTextWriter writer) { var context = StyleSheetManager.GetCurrentContext(this.Page); var controls = context?.GetAll(); if (controls != null) { foreach (var control in controls) { var styleSheets = control.GetStyleSheets(); if (styleSheets != null) { //StyleSheetManager styleSheetManager = GetStyleSheetManager(); //if (styleSheetManager != null) { foreach (var styleSheet in styleSheets) { this.Add(styleSheet); } } } } } //writer.Write($"controls: {controls!=null} {controls?.Count()??-1}"); int c = 0; //writer.Write($"<!-- Use CDN {NetworkSegmentation.GetIPSegmentType(this.GetIPAddress())} -->\r\n"); using (var designScope = new Design.DesignScope(this)) { if (this.DesignMode) { WebResourceManagement.Init(); } foreach (var styleSheet in this.References) { string name = styleSheet.Name; bool isDebug = HttpContext.Current?.IsDebuggingEnabled ?? false; bool isCDN = EnableCDN && ShouldUseCDN(); string url = styleSheet.Url; if (!string.IsNullOrEmpty(name)) { var reference = WebResourceManagement.StyleSheets?[name]; if (reference != null) { if (isCDN) { url = isDebug ? reference.CdnDebugPath : reference.CdnPath; if (isDebug && string.IsNullOrEmpty(url)) { url = reference.CdnPath; } } else { url = isDebug ? reference.DebugPath : reference.Path; if (isDebug && string.IsNullOrEmpty(url)) { url = reference.Path; } } if (string.IsNullOrEmpty(url)) { url = reference.Path; } //if (reference!=null) //{ // throw new System.Exception($"{name} Path: {reference.Path} url '{url}' isCDN: {isCDN} isDebug: {isDebug}"); //} } else if (!DesignMode) { throw new StyleSheetReferenceException($"The StyleSheet Definition for '{name}' has not been configured!"); } } else { url = isCDN ? (isDebug ? styleSheet.CdnDebugUrl : styleSheet.CdnUrl) : (isDebug ? styleSheet.DebugUrl : styleSheet.Url); } if (!string.IsNullOrEmpty(url)) { writer.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet"); writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Page.ResolveClientUrl(url)); writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css"); writer.RenderBeginTag(HtmlTextWriterTag.Link); writer.RenderEndTag(); c++; } //else //{ // writer.Write($"<!-- Not found Url from {name} -->\r\n"); //} } } //if (DesignMode) // writer.Write($"{{{this.GetType().Name}: {this.ID}. StyleSheets:{c} of {this.References.Count}}} in {WebResourceManagement.ResourcesProvider?.Name??"Not Loaded"}"); }