Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Object property binding

Reply
Thread Tools

Object property binding

 
 
Italo Gomes
Guest
Posts: n/a
 
      07-15-2008
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
better:

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.


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      07-15-2008
Hi,

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(ValidatedControlCo nverter))> _

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
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



"Italo Gomes" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 better:
>
> 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.
>



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      07-15-2008
To add, you certainly can have control type properties but you could assign
them in code...as a workaround

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Italo Gomes" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 better:
>
> 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.
>



 
Reply With Quote
 
Italo Gomes
Guest
Posts: n/a
 
      07-15-2008
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
((WebControl)context.Instance).Page.FindControl((s tring)value);

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

Any ideas?

Thank you again. I really appreciate your help.

Italo Gomes.


"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> To add, you certainly can have control type properties but you could
> assign them in code...as a workaround
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
> "Italo Gomes" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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 better:
>>
>> 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.
>>

>
>



 
Reply With Quote
 
Italo Gomes
Guest
Posts: n/a
 
      07-15-2008
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
from.

Am I right?

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


"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> 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(ValidatedControlCo nverter))> _
>
> 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
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
>
>
> "Italo Gomes" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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 better:
>>
>> 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.
>>

>
>



 
Reply With Quote
 
Italo Gomes
Guest
Posts: n/a
 
      07-15-2008
I have just found the GetStandardValues which may be what I was looking
for... (at least I hope so)


"Italo Gomes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> from.
>
> Am I right?
>
> Sorry for so many basic questions, the beggining days are not always
> easy...
>
> "Teemu Keiski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> 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(ValidatedControlCo nverter))> _
>>
>> 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
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice.com/joteke
>> http://teemukeiski.net
>>
>>
>>
>> "Italo Gomes" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 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 better:
>>>
>>> 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.
>>>

>>
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      08-03-2008
Hi,

I suggest you pick Reflector and have a look at some type converters in .NET
Framework. They are good for inspection and seeing how they can be used.

There's also a good walkthrough:

How To:Implement a Type Converter
http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"Italo Gomes" <(E-Mail Removed)> wrote in message
news:e%23$(E-Mail Removed)...
>I have just found the GetStandardValues which may be what I was looking
>for... (at least I hope so)
>
>
> "Italo Gomes" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>> from.
>>
>> Am I right?
>>
>> Sorry for so many basic questions, the beggining days are not always
>> easy...
>>
>> "Teemu Keiski" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi,
>>>
>>> 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(ValidatedControlCo nverter))> _
>>>
>>> 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
>>> AspInsider, ASP.NET MVP
>>> http://blogs.aspadvice.com/joteke
>>> http://teemukeiski.net
>>>
>>>
>>>
>>> "Italo Gomes" <(E-Mail Removed)> wrote in message
>>> news:%(E-Mail Removed)...
>>>> 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 better:
>>>>
>>>> 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.
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to property of property of object collection TS ASP .Net 3 08-31-2006 12:57 PM
"gridview Object does not match target type" error during binding collection of different type object gui.besse@gmail.com ASP .Net 2 08-06-2006 03:12 PM
Binding data to object and its nested object (ASP.NET 2.0) Piotrek ASP .Net 4 08-04-2006 10:09 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM



Advertisments