Try our conversational search powered by Generative AI!

Hiding the XFoms Data Tab in Edit Mode

Vote:
 

I am trying to hide the XForms Data Tab in Edit Mode based on certain criteria. My problem is that I can't find the tab in the controls collection using the following code:

private static void EditPanel_LoadedPage(EPiServer.UI.Edit.EditPanel sender,
                                                 EPiServer.UI.Edit.LoadedPageEventArgs e)
        {
            // find the TabStrip with id = "actionTab"   
            TabStrip actionTabStrip = ControlHelper.FindControl<TabStrip>(sender as Control, "actionTab");
            
            //call our tab manager
            SetTabs(actionTabStrip);
        }

        public static void SetTabs(TabStrip tabStrip)
        {
            if (tabStrip == null)
            {
                return;
            }

            for (int i = 0; i < tabStrip.Controls.Count; i++)
            {
                Tab tab = (Tab) tabStrip.Controls[i];
                string tabName = tab.Text.ToLower().Trim();

                // tabName is always "preview", XForms Data tab never found
            }

        }

    

I am using this blog http://world.episerver.com/Blogs/Eric-Vanderfeesten/Dates/2013/4/EditPanel-Manager/ as inspiration

#72337
Jun 13, 2013 12:33
Vote:
 

Hi Paul,

 

I did it like this:

[GuiPlugIn(Area = PlugInArea.EditPanel)]
public class RemoveXFormTab : ICustomPlugInLoader
{
	public PlugInDescriptor[] List()
	{        	
        	// Hook LoadComplete-event on EditPanel page
	        var editPanel = HttpContext.Current.Handler as EPiServer.UI.Edit.EditPanel;

	        if (editPanel != null)
        	{
	           editPanel.LoadComplete += new EventHandler(EditPanelLoadComplete);
        	}    	        

		// Never return a plugin - we don't want to add tabs.
		return new PlugInDescriptor[] { };
	}

	protected void EditPanelLoadComplete(object sender, EventArgs e)
	{
		// Find the TabStrip with id = "actionTab"
		var actionTabStrip = FindControl<TabStrip>(sender as Control, "actionTab");
		if (actionTabStrip == null) return;

		// Loop trough all tabs and locate the XFormPostings tab to hide it
		foreach (Tab tab in actionTabStrip.Controls)
		{
			if (tab.PlugInID == 0) continue;

			PlugInDescriptor desc = PlugInDescriptor.Load(tab.PlugInID);
			if(desc != null && desc.PlugInType == typeof(EPiServer.UI.Edit.XFormPostings))
			{
				tab.Visible = false;
			}
		}
	}

	// Try to locate control of type T with ID==id
	// Recurses into each childcontrol until first match is found
	protected T FindControl<T>(Control control, string id) where T : Control
	{
		var controlTest = control as T;

		if (null != controlTest && (null == id || controlTest.ID.Equals(id)))
		{
			return controlTest;
		}

		foreach (Control c in control.Controls)
		{
			controlTest = FindControl<T>(c, id);
			if (null != controlTest)
			{
				return controlTest;
			}
		}

		return null;
	}
}

    

#72344
Edited, Jun 13, 2013 13:48
Vote:
 

Thanks Tore, worked like a charm!

#72346
Jun 13, 2013 14:13
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.