Designer Support for Selecting Web Form control

P

Paul Ingles

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
works?

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
 
V

Victor Garcia Aprea [MVP]

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:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 
P

Paul Ingles

J

John Saunders

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)
context.GetService(typeof(IReferenceService));
object[] references = service.GetReferences(typeof(Control));
TypeConverter.StandardValuesCollection coll = new
TypeConverter.StandardValuesCollection(references);
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
(e-mail address removed)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top