using System; using System.Collections.Generic; using System.Linq; using System.Web; using umbraco.BasePages; using umbraco.uicontrols; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using ClientDependency.Core; namespace umbraco.presentation { /// /// Extension methods for the Umbraco BasePage /// public static class BasePageExtensions { /// /// Used to display an error message to the user and disable further execution. /// This will remove all controls from being rendered and show a feedback control with an error /// /// public static void DisplayFatalError(this BasePage page, string msg) { foreach (var ctl in page.Controls.Cast()) { if (!HideControls(ctl)) { var ctls = ctl.FlattenChildren(); foreach (var c in ctls) { HideControls(c); } } } var feedback = new Feedback(); feedback.type = Feedback.feedbacktype.error; feedback.Text = string.Format("{0}

{1}", ui.GetText("error"), msg); page.Controls.Add(feedback); } private static bool HideControls(this Control c) { if (c is MasterPage) { return false; } else if (c is UserControl || c is WebControl || c is HtmlForm) { c.Visible = false; return true; } return false; } } }