/// <summary>
    /// PreInit event handler.
    /// </summary>
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        // Init the page components
        manPortal.SetMainPagePlaceholder(plc);

        var ui = UIElementInfo.Provider.Get(QueryHelper.GetInteger("elementid", 0));

        // Clear UIContext data of element "Modules.UserInterface.Design" (put by UIElement attribute to check permissions)
        var ctx = pnlContext.UIContext;

        ctx.Data = null;
        ctx.HideControlOnError = false;

        if (ui != null)
        {
            ctx.UIElement = ui;

            // Store resource name
            ctx.ResourceName = ApplicationUrlHelper.GetResourceName(ui.ElementResourceID);

            // Provide empty object in case of editing
            if (!ui.RepresentsNew)
            {
                var objectType = UIContextHelper.GetObjectType(ctx);
                if (!String.IsNullOrEmpty(objectType))
                {
                    ctx.EditedObject = GetEmptyObject(objectType);
                }
            }

            int pageTemplateId = ui.ElementPageTemplateID;

            // If no page template is set, dont show any content
            if (pageTemplateId == 0)
            {
                RedirectToInformation(GetString("uielement.design.notemplate"));
            }

            DocumentContext.CurrentPageInfo = PageInfoProvider.GetVirtualPageInfo(pageTemplateId);

            // Set the design mode
            bool enable = (SystemContext.DevelopmentMode || (ui.ElementResourceID == QueryHelper.GetInteger("moduleId", 0) && ui.ElementIsCustom));
            PortalContext.SetRequestViewMode(ViewModeEnum.Design);

            // If displayed module is not selected, disable design mode
            if (!enable)
            {
                plc.ViewMode = ViewModeEnum.DesignDisabled;
            }

            RequestStockHelper.Add(CookieName.DisplayContentInDesignMode, PortalHelper.DisplayContentInUIElementDesignMode, true);

            ManagersContainer    = plcManagers;
            ScriptManagerControl = manScript;
        }
    }
    /// <summary>
    /// Gets HTML list code representing the <paramref name="uiElement"/> where can visitors go after the import has finished.
    /// </summary>
    /// <param name="uiElement">UI element the caption, icon and link are loaded from</param>
    /// <param name="description">Description of the element (i.e. some clarification what the application is good for)</param>
    /// <returns>HTML list code representing the <paramref name="uiElement"/> with given <paramref name="description"/></returns>
    private string GetContinueToSmartTipListContent(UIElementInfo uiElement, string description)
    {
        string applicationUrl = ApplicationUrlHelper.GetApplicationUrl(ApplicationUrlHelper.GetResourceName(uiElement.ElementResourceID), uiElement.ElementName);

        return(string.Format(@"
<li>
    <div class=""om-import-csv-next-steps-initial"">
        <i aria-hidden=""true"" class=""{0} cms-icon-100""></i>
    </div>
    <div class=""om-import-csv-next-steps-description"">
        <p class=""lead"">
            <a href=""{1}"" target=""_blank"">{2}</a>
        </p>
        <p>
            {3}
        </p>
    </div>
</li>", uiElement.ElementIconClass, UrlResolver.ResolveUrl(applicationUrl), MacroResolver.Resolve(uiElement.ElementCaption), description));
    }
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        // Get data
        if (itemData != null)
        {
            int    id                 = ValidationHelper.GetInteger(itemData["ElementID"], 0);
            int    childCount         = ValidationHelper.GetInteger(itemData["ElementChildCount"], 0);
            bool   selected           = ValidationHelper.GetBoolean(itemData["ElementSelected"], false);
            string displayName        = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(itemData["ElementDisplayName"], string.Empty)));
            string elementName        = ValidationHelper.GetString(itemData["ElementName"], string.Empty);
            int    parentID           = ValidationHelper.GetInteger(itemData["ElementParentID"], 0);
            int    resourceID         = ValidationHelper.GetInteger(itemData["ElementResourceID"], 0);
            string nodePath           = ValidationHelper.GetString(itemData["ElementIDPath"], string.Empty);
            string itemClass          = "ContentTreeItem";
            string onClickDeclaration = string.Format(" var chkElem_{0} = document.getElementById('chk_{0}'); ", id);
            string onClickCommon      = string.Format("  hdnValue.value = {0} + ';' + chkElem_{0}.checked; {1};", id, CallbackRef);
            string onClickSpan        = string.Format(" chkElem_{0}.checked = !chkElem_{0}.checked; ", id);

            // Expand for root
            if (parentID == 0)
            {
                defaultNode.Expanded = true;
            }

            if (!nodePath.EndsWith("/", StringComparison.Ordinal))
            {
                nodePath += "/";
            }

            bool chkEnabled = Enabled;
            if (!SingleModule && (ModuleID > 0))
            {
                bool isEndItem = false;
                bool isChild   = false;
                bool isParent  = false;

                var paths = treeElem.ExpandPath
                            .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                            // Add slash - select only children
                            .Select(path => path.EndsWith("/", StringComparison.Ordinal) ? path : path + "/");

                // Check expanded paths
                foreach (var path in paths)
                {
                    if (!isChild)
                    {
                        isChild = nodePath.StartsWith(path, StringComparison.InvariantCultureIgnoreCase);
                    }

                    // Module node is same node as specified in paths collection
                    isEndItem = path.Equals(nodePath, StringComparison.InvariantCultureIgnoreCase);

                    // Test for parent - expand
                    if (path.StartsWith(nodePath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        defaultNode.Expanded = true;
                        isParent             = true;
                        break;
                    }
                }

                // Display for non selected module items
                if (resourceID != ModuleID)
                {
                    // Parent special css
                    if (isParent)
                    {
                        itemClass += " highlighted disabled";
                    }
                    else
                    {
                        // Disable non parent
                        chkEnabled = false;
                        itemClass += " disabled";
                    }
                }
                else if (isEndItem)
                {
                    // Special class for end module item
                    itemClass += " highlighted";
                }
            }

            // Get button links
            string links = null;

            string nodeText;
            if (!String.IsNullOrEmpty(GroupPreffix) && elementName.StartsWith(GroupPreffix, StringComparison.InvariantCultureIgnoreCase))
            {
                if (childCount > 0 && chkEnabled)
                {
                    links = string.Format(SELECT_DESELECT_LINKS, id, "false", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                }
                nodeText = $"<span class='{itemClass}'>{displayName}</span>{links}";
            }
            else
            {
                string warning = string.Empty;

                if ((SiteName != null) && !ResourceSiteInfoProvider.IsResourceOnSite(ApplicationUrlHelper.GetResourceName(resourceID), SiteName))
                {
                    warning = UIHelper.GetAccessibleIconTag("icon-exclamation-triangle",
                                                            String.Format(GetString("uiprofile.warningmodule"), "cms." + elementName.ToLowerInvariant()),
                                                            additionalClass: "color-orange-80");
                }

                if (childCount > 0 && chkEnabled)
                {
                    links = string.Format(SELECT_DESELECT_LINKS, id, "true", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                }

                nodeText = string.Format(@"<span class='checkbox tree-checkbox'><input type='checkbox' id='chk_{0}' name='chk_{0}'{1}{2} onclick=""{3}"" /><label for='chk_{0}'>&nbsp;</label><span class='{4}' onclick=""{5} return false;""><span class='Name'>{6}</span></span>{7}</span>{8}",
                                         id,
                                         chkEnabled ? string.Empty : " disabled='disabled'",
                                         selected ? " checked='checked'" : string.Empty,
                                         chkEnabled ? onClickDeclaration + onClickCommon : "return false;",
                                         itemClass,
                                         chkEnabled ? onClickDeclaration + onClickSpan + onClickCommon : "return false;",
                                         displayName,
                                         warning,
                                         links);
            }

            defaultNode.ToolTip = string.Empty;
            defaultNode.Text    = nodeText;
        }

        return(defaultNode);
    }