• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Make new property show up in markup and in the control properties

public GlobalMethods.InfoGatherKind GatherKind
        {
            get
            {
                return GlobalMethods.igatherkind;
            }
        }

I want to be able to set the GatherKind in the markup and the control Properties.  How do I do this please?

I know it is an attribute of some sort above the property name [Persist...] or something or other.

0
Tom Knowlton
Asked:
Tom Knowlton
  • 3
1 Solution
 
Craig WagnerSoftware ArchitectCommented:
Any property that is public or protected is automatically available to the markup. If you want to be able to set it you'll need a setter in addition to the getter.

The only thing I've had to do when creating custom controls to get the property to show up is to add the CategoryAttribute to the control.


[Category( "MyCategory" )]
[DefaultValue( "" )]
[Description( "The label that will be used to prefix the data item in email. If this value is blank the object name will be used." )]
public string Label
{
    get { return properties.Label; }
    set { properties.Label = value; }
}
0
 
Tom KnowltonWeb developerAuthor Commented:
  [BrowsableAttribute(true)]
        public GlobalMethods.InfoGatherKind GatherKind
        {
            get
            {
                return GlobalMethods.igatherkind;
            }

            set
            {
                GlobalMethods.igatherkind = value;
            }
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;

                Attributes["value"] = value;
            }
        }

Open in new window




It shows up in the Properties window now but is greyed-out

and...

it still does not show up in the markup attributes (in the HTML)
0
 
Tom KnowltonWeb developerAuthor Commented:
Nevermind...


This seems to be working well...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.ComponentModel;


//Taken from
//
//http://www.codeproject.com/KB/custom-controls/ASPNET_Password_TextBox.aspx

namespace Campus_Webstore
{   

    public class TextBoxWithCustomAttributes : TextBox
    {        
        public TextBoxWithCustomAttributes()
        {
         
        }

        [Category("Kinds")]
        [BrowsableAttribute(true)]
        public GlobalMethods.InfoGatherKind GatherKind
        {
            get
            {
                return GlobalMethods.igatherkind;
            }

            set
            {
                GlobalMethods.igatherkind = value;
            }
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;

                Attributes["value"] = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            Attributes["value"] = Text;
        }
    }
}

Open in new window

0
 
Tom KnowltonWeb developerAuthor Commented:
thx!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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