Solved

Help Adding Design Time Functionality To A Custom WebControl

Posted on 2007-11-17
2
520 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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