Rock.Web.UI.Controls.GridFilter.OnInit C# (CSharp) Method

OnInit() protected method

Raises the E:System.Web.UI.Control.Init event.
protected OnInit ( EventArgs e ) : void
e System.EventArgs An object that contains the event data.
return void
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            // Get User Values
            _userPreferences = new List<UserPreference>();

            RockBlock rockBlock = this.RockBlock();
            if ( rockBlock != null )
            {
                string keyPrefix = string.Format( "grid-filter-{0}-", rockBlock.BlockId );

                foreach ( var userPreference in rockBlock.GetUserPreferences( keyPrefix ) )
                {
                    var blockKey = userPreference.Key.Replace( keyPrefix, string.Empty );
                    var keyName = blockKey.Split( new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries );
                    if ( blockKey.Contains("|") && keyName.Length == 2 )
                    {
                        // only load userPreferences that are stored in the {key}|{name} format
                        // and make sure there isn't more than one with the same key
                        if ( !_userPreferences.Any( a => a.Key == keyName[0] ) )
                        {
                            _userPreferences.Add( new UserPreference( keyName[0], keyName[1], userPreference.Value ) );
                        }
                    }
                }
            }
        }