Solved

Help Adding Design Time Functionality To A Custom WebControl

Posted on 2007-11-17
2
515 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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now