protected void SetRootNode()
    {
        if (String.IsNullOrEmpty(ElementName))
        {
            // Get the root UI element
            root = UIElementInfoProvider.GetRootUIElementInfo(ModuleName);
        }
        else
        {
            // Get the specified element
            root = UIElementInfoProvider.GetUIElementInfo(ModuleName, ElementName);
        }

        string codeName = root.ElementName.Replace(".", String.Empty).ToLowerCSafe();
        string caption  = UIElementInfoProvider.GetElementCaption(root);
        string rootUrl  = !String.IsNullOrEmpty(RootTargetURL) ? GetUrl(RootTargetURL) : GetUrl(root.ElementTargetURL);

        string rootText = caption + DevIcon;

        if (EnableRootSelect)
        {
            rootText = String.Format("<a href=\"{0}\" target=\"{1}\"><span id=\"node_{2}\" name=\"treeNode\" class=\"ContentTreeItem ContentTreeSelectedItem\"><span class=\"Name\">{3}</span></span></a>", rootUrl, TargetFrame, codeName, caption);
            treeElem.SetRoot(rootText, root.ElementID.ToString(), null, rootUrl, TargetFrame);
            treeElem.EnableRootAction = true;
        }
        else
        {
            treeElem.SetRoot(rootText, root.ElementID.ToString(), null);
        }

        treeElem.ExpandPath = root.ElementIDPath;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        String text    = String.Empty;
        String url     = TargetUrl;
        bool   enabled = true;
        String onClick = String.Empty;

        // If new element is set, load it directly, otherwise use first element with prefix 'new' in its name.
        UIElementInfo uiNew = String.IsNullOrEmpty(NewElement) ? UIContext.UIElement.GetNewElement() :
                              UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementResourceID, NewElement);

        bool   openInDialog = false;
        String dialogWidth  = null;
        String dialogHeight = null;

        if (uiNew != null)
        {
            UIContextData data = new UIContextData();
            data.LoadData(uiNew.ElementProperties);
            text    = UIElementInfoProvider.GetElementCaption(uiNew);
            enabled = UIContextHelper.CheckElementVisibilityCondition(uiNew);
            url     = ContextResolver.ResolveMacros(UIContextHelper.GetElementUrl(uiNew, UIContext));

            openInDialog = data["OpenInDialog"].ToBoolean(false);
            dialogWidth  = data["DialogWidth"].ToString(null);
            dialogHeight = data["DialogHeight"].ToString(null);

            // Set on-click for JavaScript type
            if (uiNew.ElementType == UIElementTypeEnum.Javascript)
            {
                onClick = url;
                url     = String.Empty;
            }
            else
            {
                // For URL append dialog hash if needed
                url = UIContextHelper.AppendDialogHash(UIContext, url);
            }
        }

        // If url is non empty add action
        if (((url != String.Empty) || (onClick != String.Empty)) && (HeaderActions != null))
        {
            HeaderActions.AddAction(new HeaderAction()
            {
                Text          = GetString(text),
                RedirectUrl   = url,
                Enabled       = enabled,
                OnClientClick = onClick,
                OpenInDialog  = openInDialog,
                DialogWidth   = dialogWidth,
                DialogHeight  = dialogHeight
            });
        }
    }
    /// <summary>
    /// Page pre-render event handling.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        // Add extra header actions
        ICMSPage page = Control.Page as ICMSPage;

        if (page != null)
        {
            var importElement = UIElementInfoProvider.GetUIElementInfo("CMS", "ImportSiteOrObjects");
            if (importElement != null)
            {
                page.HeaderActions.AddAction(new HeaderAction
                {
                    RedirectUrl = UIContextHelper.GetElementUrl(importElement, false),
                    Text        = UIElementInfoProvider.GetElementCaption(importElement)
                });
            }

            var exportElement = UIElementInfoProvider.GetUIElementInfo("CMS", "Export");
            if (exportElement != null)
            {
                page.HeaderActions.AddAction(new HeaderAction
                {
                    RedirectUrl = UIContextHelper.GetElementUrl(exportElement, false),
                    Text        = UIElementInfoProvider.GetElementCaption(exportElement)
                });
            }

            var exportHistory = UIElementInfoProvider.GetUIElementInfo("CMS", "ExportHistory");
            if (exportHistory != null)
            {
                page.HeaderActions.AddAction(new HeaderAction
                {
                    RedirectUrl = UIContextHelper.GetElementUrl(exportHistory, false),
                    Text        = UIElementInfoProvider.GetElementCaption(exportHistory)
                });
            }
        }
    }
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        if (itemData != null)
        {
            UIElementInfo uiElement = new UIElementInfo(itemData);

            if (!UIContextHelper.CheckElementAvailabilityInUI(uiElement))
            {
                return(null);
            }

            // Check permissions
            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement(uiElement.ElementResourceID, uiElement.ElementName, ModuleAvailabilityForSiteRequired))
            {
                defaultNode = RaiseOnNodeCreated(uiElement, defaultNode);

                String url = UIContextHelper.GetElementUrl(uiElement, UIContext);
                if (uiElement.ElementType != UIElementTypeEnum.PageTemplate)
                {
                    url = URLHelper.RemoveParameterFromUrl(url, "displaytitle");
                }

                // If url is empty -> don't show
                if (defaultNode == null || String.IsNullOrEmpty(url))
                {
                    return(null);
                }

                // Prepare node info
                string caption     = UIElementInfoProvider.GetElementCaption(uiElement);
                string targetFrame = !String.IsNullOrEmpty(defaultNode.Target) ? defaultNode.Target : TargetFrame;
                string codeName    = uiElement.ElementName.Replace(".", String.Empty).ToLowerCSafe();

                UIElementInfo sel = UIContextHelper.CheckSelectedElement(uiElement, UIContext);
                if (sel != null)
                {
                    SelectedNode = uiElement.ElementName;

                    String selectionSuffix = ValidationHelper.GetString(UIContext["selectionSuffix"], String.Empty);
                    String spUrl           = UIContextHelper.GetElementUrl(sel, UIContext);
                    spUrl = URLHelper.AppendQuery(spUrl, selectionSuffix);

                    // Append object ID
                    url = URLHelper.UpdateParameterInUrl(url, "objectid", UIContext.ObjectID.ToString());

                    StartingPage = URLHelper.UpdateParameterInUrl(spUrl, "displaytitle", "true");
                }

                // Set node
                defaultNode.Target      = targetFrame;
                defaultNode.NavigateUrl = GetUrl(url);
                defaultNode.Text        = defaultNode.Text.Replace(NODE_CODENAME_MACRO, codeName);

                totalNodes++;

                // Set first child node to be selected if root cant be selected
                if (!EnableRootSelect && string.IsNullOrEmpty(SelectedNode))
                {
                    // Is a page node (with page url)
                    if (url != ApplicationUrlHelper.COLLAPSIBLE_EMPTY_PARENT_ELEMENT_URL)
                    {
                        SelectedNode = uiElement.ElementName;
                    }
                    else
                    {
                        // Try to display a child element
                        if (uiElement.ElementChildCount > 0)
                        {
                            defaultNode.Expanded = true;
                        }
                    }
                }

                // If url is '@' don't redirect, only collapse children
                if (uiElement.ElementTargetURL == ApplicationUrlHelper.COLLAPSIBLE_EMPTY_PARENT_ELEMENT_URL)
                {
                    // Onclick simulates click on '+' or '-' button
                    const string onClick = "onClick=\"var js = $cmsj(this).parents('tr').find('a').attr('href');eval(js);return false; \"";
                    defaultNode.Text = "<span id=\"node_" + uiElement.ElementName + "\" class=\"ContentTreeItem \"" + onClick + " ><span class=\"Name\">" + ResHelper.LocalizeString(caption) + "</span></span>";
                }

                return(defaultNode);
            }
        }

        return(null);
    }