Designer Support for Selecting Web Form control

Discussion in 'ASP .Net Building Controls' started by Paul Ingles, Jul 19, 2003.

  1. Paul Ingles

    Paul Ingles Guest

    I've got a validator control that has somewhat limited designer support. It
    has an additional property that contains a string identifying another
    control on the form, e.g. "MyListBox".

    The BaseValidator control has a ControlToValidate property that does exactly
    what I need it to for this property, but was wondering how it actually

    I'd like it so that the VS.NET designer displays a drop-down list of all
    controls on the web form that are of type MyListBoxControl, so the developer
    can just select it and hey presto.

    Is this done using a custom designer, a custom type editor?

    Thanks for all suggestions,
    Paul Ingles, Jul 19, 2003
    1. Advertisements

  2. Hi Paul,

    You need a custom type converter. The BaseValidator.ControlToValidate
    property has a type converter of type
    System.Web.UI.WebControls.ValidatedControlConverter. This custom type
    converter does examine every control looking if they have the
    ValidationPropertyAttribute applied.

    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.
    Victor Garcia Aprea [MVP], Jul 19, 2003
    1. Advertisements

  3. Paul Ingles

    Teemu Keiski Guest

    Teemu Keiski, Jul 19, 2003
  4. Paul Ingles

    Paul Ingles Guest

    Paul Ingles, Jul 19, 2003
  5. I looked at the examples on ASP.NET, and have a suggestion. I similarly have
    a control which has a property which needs to be the ID of one of the other
    controls on the page. I used a TypeConverter derived from StringConverter to
    do this.

    However, instead of searching context.Container.Components, I used the
    IReferenceService. Here's the code in C#:

    public override TypeConverter.StandardValuesCollection
    GetStandardValues(ITypeDescriptorContext context)
    IReferenceService service = (IReferenceService)
    object[] references = service.GetReferences(typeof(Control));
    TypeConverter.StandardValuesCollection coll = new
    return coll;

    The following is an attempt to translate that into VB, but I won't have
    tested it:

    Public Overrides Function GetStandardValues(context as
    ITypeDescriptorContext) as TypeConverter.StandardValuesCollection
    Dim service as IReferenceService =
    CType(context.GetService(GetType(IReferenceService)), IReferenceService)
    Dim references() as Object = service.GetReferences(GetType(Control))
    Dim coll as New TypeConverter.StandardValuesCollection(references)
    Return coll
    End Function

    John Saunders
    John Saunders, Jul 19, 2003
    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.