protected internal override void CreateChildControls()
        {
            ControlCollection controls = Controls;

            controls.Clear();
            EditorControls.Clear();

            object editableObject = GetEditableObject();

            if (editableObject != null)
            {
                foreach (PropertyDescriptor pd in GetEditableProperties(editableObject, true))
                {
                    Control editorControl = CreateEditorControl(pd);
                    EditorControls.Add(editorControl);
                    Controls.Add(editorControl);
                }
                _errorMessages = new string[EditorControls.Count];
            }

            // We don't need viewstate enabled on our child controls.  Disable for perf.
            foreach (Control c in controls)
            {
                c.EnableViewState = false;
            }
        }
Ejemplo n.º 2
0
        // Internals //////////////////////////////////////////////////////////////
        private void CollectEditableProperties(object editableObject)
        {
            _groupProperties = new Dictionary <string, List <PropertyDescriptor> >();

            var controls = Controls;

            controls.Clear();
            EditorControls.Clear();
            controls.Add(new PlaceHolder());
            var properties = GetEditableProperties(editableObject);

            // grouping
            foreach (PropertyDescriptor descriptor in properties)
            {
                if ((this.HiddenProperties != null) && (this.HiddenProperties.Contains(descriptor.Name)))
                {
                    continue;
                }

                var categoryTitle = GetCategoryTitle(descriptor);
                if (HiddenCategories == null || !HiddenCategories.Contains(categoryTitle))
                {
                    if (!String.IsNullOrEmpty(categoryTitle))
                    {
                        List <PropertyDescriptor> categoryValue = null;
                        categoryValue = _groupProperties.ContainsKey(categoryTitle) ? _groupProperties[categoryTitle] : new List <PropertyDescriptor>();

                        categoryValue.Add(descriptor);
                        if (!_groupProperties.ContainsKey(categoryTitle))
                        {
                            _groupProperties.Add(categoryTitle, categoryValue);
                        }
                    }
                }

                if (_categories.Contains(categoryTitle) || String.IsNullOrEmpty(categoryTitle))
                {
                    continue;
                }
                _categories.Add(categoryTitle);
            }

            // create controls
            var editorControls = new PlaceHolder {
                ID = "GroupProperties", EnableViewState = false
            };

            foreach (var entry in _groupProperties)
            {
                var title = entry.Key;
                entry.Value.Sort(new WebOrderComparer());
                var descriptors = entry.Value;

                if (String.IsNullOrEmpty(title) || descriptors == null)
                {
                    continue;
                }

                var groupControl = new PropertyFieldPanel {
                    Title = title
                };
                groupControl.EnableViewState = false;
                foreach (var descriptor in descriptors)
                {
                    var editorControl = CreateEditorControl(descriptor);
                    if (editorControl == null)
                    {
                        continue;
                    }
                    editorControl.EnableViewState = false;
                    groupControl.Controls.Add(editorControl);
                }
                if (groupControl.Controls.Count > 0)
                {
                    editorControls.Controls.Add(groupControl);
                }
            }
            if (editorControls.Controls.Count == 0)
            {
                return;
            }
            EditorControls.Add(editorControls);
            controls.Add(editorControls);
        }