Click here to Skip to main content
15,036,145 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to create rich design time control for ASP.NET in Visual Studio 2013(2). Unfortunately I can't get to work even simple property attributes as Description. Especially I need to add custom editor to Visual PropertyGrid (when you select control in designer or source of file and press F4). I managed to get this working 1 for hundred tries, completely unrelated as far as I can tell. For example when I created new control, with almost the same code, add it to the page, build and try F4. Or after adding new completely unrelated property to control or swapping base class of control. Even when this work, any change to code, build and another try break previous working solution and you cannot go back to it because it do not work anymore. As far as I can tell (after some research) you can't debug those editors, developing it is like walking in complete dark.

Code below compiles and runs in a browser. To test it there is need to add System.Windows.Forms (?!) and System.Drawing references.

Control code:

using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Globalization;
using System.Web.UI;
using System.Windows.Forms.Design;
using editors;

namespace WebApplication1.Controls
    public class UC : Control
        [Description("test prop")]
        [Editor(typeof(Editor), typeof(UITypeEditor))]
        public string test1 { get; set; }

namespace editors
    public class Editor : UITypeEditor
        private IWindowsFormsEditorService editorService;

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
            return UITypeEditorEditStyle.DropDown;

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            value = "test1";
            if (provider != null)
                editorService =
                    as IWindowsFormsEditorService;
            if (editorService != null)
                var listBox = new System.Windows.Forms.ListBox();
                listBox.SelectedValueChanged += listBox_SelectedValueChanged;

                value = listBox.SelectedItem;
            return value;

        void listBox_SelectedValueChanged(object sender, EventArgs e)
            if (editorService != null)

Web forrm code:
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register TagPrefix="uc" Namespace="WebApplication1.Controls" Assembly="WebApplication3" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <uc:UC runat="server"></uc:UC>

Web config:

<?xml version="1.0"?>

  For more information on how to configure your ASP.NET application, please visit

      <compilation debug="true" targetFramework="4.5">
          <add assembly="System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <httpRuntime targetFramework="4.5" />


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900