[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Help Adding Design Time Functionality To A Custom WebControl

Experts,

I recently began making a few custom WebControls and wanted to get some advice on how to enhance the design time functionality in Visual Studio. Specifically I would like to know how to create a list of pre-defined options for a property. Much like "server" appears when you type runat="

Also, I would like to know exactly how to work with an enum value at design time. A great example of this is the TextBoxMode enum for the TextBox asp.net control. When you declare the control in an .aspx page, you pass a string value TextMode="singleline". However, the value is actually an enum:

TextBox tb = new TextBox();
tb.TextMode = TextBoxMode.SingleLine;

I have done a little digging, but most of what I find is the basic "this is how to add a title and description to your class" tutorials. Hopefully I can find one of you custom control experts that can point me in the right direction. Thanks much for your time so far!

~ C
0
clickclickbang
Asked:
clickclickbang
1 Solution
 
kosturdurCommented:
Hi clickclickbang,
I have searched a lot of sources for a long time at last I found some solutions;
If you have a bool,  URL, Files, Folders, Dates properties the editor comes without any additional code and also there are some editors that help developer to choose the desired item from a list in "Property Window"
like a connection string editor;

      [Editor("Microsoft.VSDesigner.Data.ADO.Design.OleDbConnectionStringEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
       
      [Editor("Microsoft.VSDesigner.Data.SQL.Design.SqlConnectionStringEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]

-->Basically what an custom editor does is offer a GUI way to edit your custom
property, you only need to write your own custom editor if none of the
built-in editors works for you. You already have an editor for URL, Files,
Folders, Dates, etc, etc.<--
http://www.dotnet247.com/247reference/msgs/15/76976.aspx

For your first question;
A custom editor should be formed by enums like;

You can use a structure like that;
        public enum MyEnum
        {
            Foo,
            Bar
        }
        private MyEnum m_eFooBar = MyEnum.Foo;

        [Bindable(true)]
        [Category("Misc")]
        [DefaultValue("Foo")]
        [Localizable(true)]
        public MyEnum FooBar
        {
            get
            {

                return m_eFooBar;
            }

            set
            {
                m_eFooBar = value;
            }
        }

so the developer must choose two values from a dropdownlist (Bar,Foo).


Or I solve some kind of thing by adding [Description] to int values that developer enters like;
        [Bindable(true)]
        [Category("Misc")]
        [DefaultValue("0")]
        [Localizable(true)]
        [Description("Empty = 0,Object = 1,DBNull = 2,Boolean = 3,Char = 4,SByte = 5,Byte = 6,Int16 = 7,UInt16 = 8,Int32 = 9,UInt32 = 10,Int64 = 11,UInt64 = 12,Single = 13,Double = 14,Decimal = 15,DateTime = 16,String = 18")]
        public virtual int SPParameterType
        {
            get
            {
                if (ViewState["SPParameterType"] == null)
                {
                    return 0;
                }
                else
                {
                    return (int)ViewState["SPParameterType"];
                }
            }
            set
            {
                ViewState["SPParameterType"] = value;
            }
        }


For your second question you should create a stump that returns the specific Type like;
    private TextBoxModeType GetTextBoxModeType(int p)
    {
        switch (p)
        {
            case 0:
                return TextBoxMode.SingleLine;
            case 1:
                return TextBoxMode.MultiLine;
            case 2:
                return TextBoxMode.XXXX;
            case 3:
                return TextBoxMode.YYYY;
            case 4:
                return TextBoxMode.ZZZZ;
            default:
                return TextBoxMode.SingleLine;
        }
    }
and use it like;
GetTextBoxModeType(ASPxComboBox1.SelectedIndex)
HTH,
0
 
clickclickbangAuthor Commented:
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now