protected override void OnLoad(EventArgs e) { string customStyleSheet = AppContext.AppSettings.CustomStyleSheet; if (!String.IsNullOrEmpty(customStyleSheet)) { HtmlHead head = FindControl("head") as HtmlHead; if (head == null && Master != null) { head = Master.FindControl("head") as HtmlHead; } if (head != null) { if (AppRelativeVirtualPath.StartsWith("~/Admin/") && customStyleSheet.ToLower().StartsWith("styles/")) { customStyleSheet = "../" + customStyleSheet; } HtmlLink customLink = new HtmlLink(); head.Controls.Add(customLink); customLink.Href = customStyleSheet; customLink.Attributes["type"] = "text/css"; customLink.Attributes["rel"] = "Stylesheet"; } } base.OnLoad(e); }
protected override void OnInit(EventArgs e) { // UserControl without Template if (string.IsNullOrEmpty(AppRelativeVirtualPath)) { return; } ITemplate template = null; var culture = CultureInfo.CurrentCulture.Name; // Trying to find a valid template path in a cache. var key = string.Concat(culture, AppRelativeVirtualPath); var appRelativeVirtualPath = Cache[key] as string; if (string.IsNullOrEmpty(appRelativeVirtualPath)) { // The template path not found in cache, creating a new template path with current culture. appRelativeVirtualPath = AppRelativeVirtualPath.Replace(".ascx", $".{culture}.ascx"); try { // Trying to load the localized template. template = LoadTemplate(appRelativeVirtualPath); Cache[key] = appRelativeVirtualPath; } catch { // The localized template not found, will be use default. Cache[key] = appRelativeVirtualPath = AppRelativeVirtualPath; } } if (template == null && string.CompareOrdinal(appRelativeVirtualPath, AppRelativeVirtualPath) != 0) { template = LoadTemplate(appRelativeVirtualPath); } // Bind template with the UserControl if (template != null) { //template.InstantiateIn(this); } base.OnInit(e); }
/// <summary> /// 添加当前页的JS和CSS /// </summary> private void AddCurrentPageJsCss() { var cssPath = AppRelativeVirtualPath.Replace(".aspx", ".css"); var jsPath = AppRelativeVirtualPath.Replace(".aspx", ".js"); if (File.Exists(Server.MapPath(cssPath))) { cssPath = cssPath.Replace("~", ""); AddCss(cssPath, cssPath, cssPath); } if (File.Exists(Server.MapPath(jsPath))) { jsPath = jsPath.Replace("~", ""); AddJs(jsPath, jsPath, jsPath); } }
private void serverTransfer() { string actualFile = Server.MapPath(AppRelativeVirtualPath); string redirectFile = Server.MapPath(Context.Request.FilePath); string baseSiteVirtualPath = HttpRuntime.AppDomainAppVirtualPath; if (actualFile != redirectFile) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); string actionUrl = string.Format("'{0}'", baseSiteVirtualPath + AppRelativeVirtualPath.Replace("~", string.Empty)); sb.Append("Sys.Application.add_load(function(){"); sb.Append(" var form=Sys.WebForms.PageRequestManager.getInstance()._form"); sb.Append(" form._initialAction = " + actionUrl + ";"); sb.Append(" form.action = " + actionUrl + ";"); sb.Append("});"); ClientScript.RegisterStartupScript(this.GetType(), "serverTransfer", sb.ToString(), true); } }