/// <summary> /// Raises the <see cref="E:Init" /> event. /// </summary> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected override void OnInit( EventArgs e ) { Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage; if ( dialogPage != null ) { dialogPage.OnSave += new EventHandler<EventArgs>( masterPage_OnSave ); } try { int blockId = Convert.ToInt32( PageParameter( "BlockId" ) ); Block _block = new BlockService( new RockContext() ).Get( blockId ); if ( _block.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ) ) { phAttributes.Controls.Clear(); phAdvancedAttributes.Controls.Clear(); _block.LoadAttributes(); if ( _block.Attributes != null ) { foreach ( var attributeCategory in Rock.Attribute.Helper.GetAttributeCategories( _block ) ) { if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("advanced", StringComparison.OrdinalIgnoreCase)) { Rock.Attribute.Helper.AddEditControls( string.Empty, attributeCategory.Attributes.Select( a => a.Key ).ToList(), _block, phAdvancedAttributes, string.Empty, !Page.IsPostBack, new List<string>()); } else { Rock.Attribute.Helper.AddEditControls( attributeCategory.Category != null ? attributeCategory.Category.Name : string.Empty, attributeCategory.Attributes.Select( a => a.Key ).ToList(), _block, phAttributes, string.Empty, !Page.IsPostBack, new List<string>() ); } } } } else { DisplayError( "You are not authorized to edit this block", null ); } } catch ( SystemException ex ) { DisplayError( ex.Message, "<pre>" + ex.StackTrace + "</pre>" ); } base.OnInit( e ); }