?
Solved

Help Adding Design Time Functionality To A Custom WebControl

Posted on 2007-11-17
2
Medium Priority
?
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
kosturdur earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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