/// <summary>
        ///
        /// </summary>
        private void PopulateControlsFromEntity()
        {
            IGenericCatWebControl correspondingControl = null;

            foreach (PropertyInfo entityProperty in entityProperties)
            {
                correspondingControl = LookupControlByEntityPropertyName(entityProperty.Name);
                if (correspondingControl == null)
                {
                    continue;
                }

                PopulateControlFromEntity(correspondingControl, entityProperty);
            }
        }
        private void PopulateControlFromEntity(IGenericCatWebControl correspondingControl, PropertyInfo entityProperty)
        {
            correspondingControl.SetDataSource(entityProperty.GetCustomAttributes(typeof(ReferenceMappingAttribute), false));

            object value = entityProperty.GetValue(_Entity, null);

            //If the catalogue is in add mode, the value is numeric and null, do not populate the catalogue. In all other situations.
            //populate the control with the corresponding value
            if (!(!_EditMode && ApplicationUtils.AssertValueIsNumeric(value) && ApplicationUtils.AssertValueIsNull(value)))
            {
                if (!(correspondingControl is IndCatTextBox && entityProperty.Name == "Rank" && !_EditMode))
                {
                    correspondingControl.SetValue(value);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        private void CreateControlDictionaryForUpdate()
        {
            IGenericCatWebControl correspondingControl = null;

            foreach (PropertyInfo entityProperty in entityProperties)
            {
                correspondingControl = LookupControlByEntityPropertyName(entityProperty.Name);
                if (correspondingControl == null)
                {
                    continue;
                }

                //add to the dictionary that will be used for update
                PropertyToControlDictionary.Add(entityProperty, correspondingControl);
            }
        }
        private void LayoutAddCustomValidators()
        {
            IGenericCatWebControl correspondingControl = null;

            foreach (PropertyInfo entityProperty in entityProperties)
            {
                correspondingControl = LookupControlByEntityPropertyName(entityProperty.Name);

                if (correspondingControl == null)
                {
                    continue;
                }

                //Add a validator to this control, if it is not checkbox or label
                if (!(correspondingControl is IndCheckBox || correspondingControl is IndLabel))
                {
                    AddValidators(entityProperty, (Control)correspondingControl);
                }
            }
        }
        private IGenericCatWebControl LookupControlByEntityPropertyName(String name)
        {
            IGenericCatWebControl correspondingControl = null;
            IGenericCatWebControl lookupControl        = null;

            //look for corresponding control by name
            foreach (Control ctl in this.Controls)
            {
                if (ctl is IGenericCatWebControl)
                {
                    lookupControl = (IGenericCatWebControl)ctl;
                    if (lookupControl.EntityProperty == name)
                    {
                        correspondingControl = lookupControl;
                        break;
                    }
                }
            }

            return(correspondingControl);
        }