Solved

Help Adding Design Time Functionality To A Custom WebControl

Posted on 2007-11-17
2
521 Views
Last Modified: 2012-06-22
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
Comment
Question by:clickclickbang
2 Comments
 
LVL 5

Accepted Solution

by:
kosturdur earned 500 total points
ID: 20307734
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
 
LVL 1

Author Closing Comment

by:clickclickbang
ID: 31409781
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question