Removing a property from a custom control derived from TextBox

Discussion in 'ASP .Net Building Controls' started by mc, Mar 10, 2007.

  1. mc

    mc Guest

    I have created a Custom control which automatically grows a TextBox to
    fit the text that is being entered, consequently this control must be a
    MultiLine TextBox. I would like to remove the "TextMode" Property, the
    closest I have achieved so far is to change the property to a Get only one.

    Is there a better solution?




    public class AutoResizeTextBox : System.Web.UI.WebControls.TextBox
    public override TextBoxMode TextMode
    return base.TextMode;

    <snip>Rest of Code</snip>
    mc, Mar 10, 2007
    1. Advertisements

  2. Hello MC,

    As for hidding a property(function) in base class, so far the .net
    framework programming language (C# and VB.NET) doesn't provide a direct
    means to do this. What you can get is use a "new" keyword (in C#) to
    redefine a property(method) and them use some .NET specific attribute to
    decorate it.

    For example ,you can use the "BrowsableAttribute" to make your control's
    "Text" property invisible in IDE designer's property windows. You can also
    use "ObsoleteAttribute" to make the property unusable(report error at
    compile time if you try using it). e.g.


    public class MyTextBox :TextBox
    public MyTextBox()


    [Obsolete("This property is no longer used in this control", true)]
    public new string Text
    get { return "not used..."; }


    #ObsoleteAttribute Class

    #BrowsableAttribute Class

    Hope this helps some.


    Steven Cheng

    Microsoft MSDN Online Support Lead


    Get notification to my posts through email? Please refer to

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Mar 12, 2007
    1. Advertisements

  3. mc

    mc Guest

    Over the weekend I'd spotted the EditorBrowsable and Browsable
    attributes, but I've not come across the Obsolete attribute. That along
    with the new keyword does the job nicely.

    It's been pointed out elsewhere that someone can cast my control as a
    TextBox and still access the property.

    Thank you for not launching into a philosophical OO rant about how bad
    it is to try and remove an inherited property!


    mc, Mar 12, 2007
  4. You're welcome ;-)


    Steven Cheng

    Microsoft MSDN Online Support Lead
    Steven Cheng[MSFT], Mar 12, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.