/// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage;
            if (dialogPage != null)
            {
                dialogPage.ValidationGroup = this.BlockValidationGroup;
            }

            valSummaryTop.ValidationGroup = this.BlockValidationGroup;

            // Set the validation group on any custom settings providers.
            SetValidationGroup(CustomSettingsProviders.Values.ToArray(), this.BlockValidationGroup);

            int?blockId = PageParameter("BlockId").AsIntegerOrNull();

            if (!blockId.HasValue)
            {
                return;
            }

            var       _block = BlockCache.Get(blockId.Value);
            SiteCache _site  = null;

            // Get site info from Page -> Layout -> Site
            if (_block.Page.IsNotNull())
            {
                _site = SiteCache.Get(_block.Page.SiteId);
            }
            else if (_block.Layout.IsNotNull())
            {
                _site = SiteCache.Get(_block.Layout.SiteId);
            }
            else if (_block.SiteId.HasValue)
            {
                _site = SiteCache.Get(_block.SiteId.Value);
            }

            // Change Pre/Post text labels if this is a mobile block
            if (_site.IsNotNull() && _site.SiteType == SiteType.Mobile)
            {
                cePostHtml.Label = "Post-XAML";
                cePreHtml.Label  = "Pre-XAML";
            }

            var blockControlType = _block.BlockType.GetCompiledType();

            this.ShowCustomGridColumns = typeof(Rock.Web.UI.ICustomGridColumns).IsAssignableFrom(blockControlType);
            this.ShowCustomGridOptions = typeof(Rock.Web.UI.ICustomGridOptions).IsAssignableFrom(blockControlType);
            this.ShowMobileOptions     = _block.Attributes.Any(a => a.Value.Categories.Any(c => c.Name == "custommobile"));

            if (!Page.IsPostBack && _block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                if (_block.Attributes != null)
                {
                    avcAdvancedAttributes.IncludedCategoryNames = new string[] { "advanced" };
                    avcAdvancedAttributes.AddEditControls(_block);

                    avcMobileAttributes.IncludedCategoryNames = new string[] { "custommobile" };
                    avcMobileAttributes.AddEditControls(_block);

                    avcAttributes.ExcludedCategoryNames = new string[] { "advanced", "customsetting", "custommobile" };
                    avcAttributes.AddEditControls(_block);
                }

                foreach (var kvp in CustomSettingsProviders)
                {
                    kvp.Key.ReadSettingsFromEntity(_block, kvp.Value);
                }

                rptProperties.DataSource = GetTabs(_block.BlockType);
                rptProperties.DataBind();

                tbBlockName.Text = _block.Name;
                tbCssClass.Text  = _block.CssClass;
                cePreHtml.Text   = _block.PreHtml;
                cePostHtml.Text  = _block.PostHtml;

                // Hide the Cache duration block for now;
                tbCacheDuration.Visible = false;
                //tbCacheDuration.Text = _block.OutputCacheDuration.ToString();

                pwCustomGridColumns.Visible   = this.ShowCustomGridColumns;
                tglEnableStickyHeader.Visible = this.ShowCustomGridOptions;

                if (this.ShowCustomGridColumns)
                {
                    CustomGridColumnsConfigState = _block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>() ?? new CustomGridColumnsConfig();
                    BindCustomColumnsConfig();
                }
                else
                {
                    CustomGridColumnsConfigState = null;
                }

                if (this.ShowCustomGridOptions)
                {
                    tglEnableStickyHeader.Checked            = _block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean();
                    tglEnableDefaultWorkflowLauncher.Checked = _block.GetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey).AsBoolean();

                    CustomActionsConfigState = _block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey).FromJsonOrNull <List <CustomActionConfig> >();
                    BindCustomActionsConfig();
                }
                else
                {
                    CustomActionsConfigState = null;
                }

                ShowSelectedPane();
            }

            base.OnLoad(e);
        }