Object property binding


Italo Gomes

Hello there,

I'm new on creating WebControls and I'm having problems trying to assign
two webcontrols that I have developed by using a property. Let me explain it

In the first WebControl I declared a property like the following:

private WebControl2 object2;
public WebControl2 Object2
get { return object2; }
set { object2 = value; }

The property display correctly in the Property Grid, but when I try to
run the application, I get an error message saying that it's not possible to
create an instance of WebControl2 from a string. I have a similar pair of
controls for WinForms and it works perfectly there without doing anything
else, so I don't have any idea of what's wrong.

Can anyone point me some tutorial/how-to/walkthrough about this subject?

Thank you in advance.

Italo Gomes.

Teemu Keiski


ASP.NET uses markup to describe these relationships and settings of controls
whatsoever, e.g you do for example with validation controls

<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextBox1"

If you inspect the ControlToValidate property further, you'll find it is a
string, having a typeconverter defined

<TypeConverterAttribute(GetType(ValidatedControlConverter))> _

which works under the cover so that validator control actually calls
FindControl with the ID to get reference to the target control.
ValidatedControlConverter is for picking the list of available controls on
the page.

Point is that ASP.NET pages are described through markup and it just cannot
provide live reference to controls, since they actually live on the server
and not in your markup (which is just "meta" description of what lives on
the server).

Teemu Keiski

To add, you certainly can have control type properties but you could assign
them in code...as a workaround

Italo Gomes

Hi there, Teemu,

Thank you for your reply.

I was aware of TypeConverters, and actually tried creating one, but it
did not help. It's not clear to me what I should do in the ConvertFrom
method in this case.

At first I tried using the context parameter to find the Page object and
then using the FindControl to get the object reference. But after that, the
designer started to say that it could not create an instance of the class
based on the string ID.

I tried the following code:

if (value is string)

return base.ConvertFrom(context, culture, value);

Any ideas?

Thank you again. I really appreciate your help.

Italo Gomes.

Italo Gomes

I was thinking about the string value to store the object's ID. I agree this
would make it easier to deal with the fact of the way ASP.NET stores the
relationships, but in this case I miss the part that shows the available and
compatible objects in the property grid as a combo-box.

I mean, there should be some kind of helper class to scan the entire page
after the object's ID which are or derive from the class the property is

Am I right?

Sorry for so many basic questions, the beggining days are not always easy...

Italo Gomes

I have just found the GetStandardValues which may be what I was looking
for... (at least I hope so) :)

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

Latest member

Latest Threads