Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
[EPiServer.PlugIn.GuiPlugIn(DisplayName = "hidden",
Description = "edit hooks",
Area = EPiServer.PlugIn.PlugInArea.EditPanel,
Url = "~/templates/Plugins/EditHiddenHooks.ascx")
]
public class EditHiddenHooks : UserControlBase, ICustomPlugInLoader
{
PlugInDescriptor[] ICustomPlugInLoader.List()
{
PlugInDescriptor[] plugins = new PlugInDescriptor[0];
this.PageBase.PreRender += new EventHandler(Page_PreRender);
return plugins;
}
private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Page_PreRender(object sender, EventArgs e)
{
// first Find active tab control
//index 0 = PreView
//index 1 = Edit
//index 2 = VersionList
Page page = (Page)sender;
if (page != null && page.Controls.Count > 0)
{
int activeTab = GetActiveTab(page.Controls[0]);
switch (activeTab)
{
//We are only interested to handle publish button on PreView or Edit tab
case 0:
break;
case 1:
MarkPageAsChanged(page.Controls[0]);
break;
default:
break;
}
}
}
//Recursive function that finds tab ctrl and returns index of the currently active tab
private int GetActiveTab(Control ctrl)
{
if (ctrl is EPiServer.SystemControls.Tab)
{
EPiServer.SystemControls.Tab command = (EPiServer.SystemControls.Tab)ctrl;
if (command.Active)
return command.Index;
}
//If not found check child ctls
foreach (Control child in ctrl.Controls)
{
int tab = GetActiveTab(child);
if (tab != -1)
return tab;
}
return -1;
}
//Function that finds ctrl of type CommandTool (publish button e.g.) with name Publish.
//It will then add a client javascript to the control for clientside confirmation
private void MarkPageAsChanged(Control ctrl)
{
System.Web.UI.Control c = FindCheckBoxRecursive(ctrl, "PageChangedOnPublish");
if (c != null)
((CheckBox)c).Checked = true;
}
///
/// Search recurisively for a control.
///
/// Root control whos children and sub children will be searched.
/// The ID of the control to search for.
/// Returns found control or null if no control is found.
private System.Web.UI.Control FindCheckBoxRecursive(System.Web.UI.Control RootControl, String ControlID)
{
if (RootControl != null)
{
System.Web.UI.Control tmpCtrl = RootControl.FindControl(ControlID);
if (tmpCtrl != null && tmpCtrl is System.Web.UI.WebControls.CheckBox)
return tmpCtrl;
foreach (System.Web.UI.Control c in RootControl.Controls)
{
tmpCtrl = FindCheckBoxRecursive(c, ControlID);
if (tmpCtrl != null && tmpCtrl is System.Web.UI.WebControls.CheckBox)
return tmpCtrl;
}
}
return null;
}
}