[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Italo Gomes

7/15/2008 5:46:00 PM

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.


6 Answers

Teemu Keiski

7/15/2008 7:43:00 PM

0

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(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
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...



"Italo Gomes" <italogomes@ig.com.br> wrote in message
news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
> 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.
>


Teemu Keiski

7/15/2008 7:44:00 PM

0

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....
http://teemu...

"Italo Gomes" <italogomes@ig.com.br> wrote in message
news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
> 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.
>


Italo Gomes

7/15/2008 8:07:00 PM

0

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((string)value);

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

Any ideas?

Thank you again. I really appreciate your help.

Italo Gomes.


"Teemu Keiski" <joteke@aspalliance.com> wrote in message
news:ex2PTMr5IHA.4560@TK2MSFTNGP04.phx.gbl...
> 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....
> http://teemu...
>
> "Italo Gomes" <italogomes@ig.com.br> wrote in message
> news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>
>


Italo Gomes

7/15/2008 8:14:00 PM

0

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" <joteke@aspalliance.com> wrote in message
news:uj2N4Lr5IHA.1892@TK2MSFTNGP06.phx.gbl...
> 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(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
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice....
> http://teemu...
>
>
>
> "Italo Gomes" <italogomes@ig.com.br> wrote in message
> news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>
>


Italo Gomes

7/15/2008 8:54:00 PM

0

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


"Italo Gomes" <italogomes@ig.com.br> wrote in message
news:O7A0vcr5IHA.4776@TK2MSFTNGP05.phx.gbl...
>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" <joteke@aspalliance.com> wrote in message
> news:uj2N4Lr5IHA.1892@TK2MSFTNGP06.phx.gbl...
>> 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(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
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice....
>> http://teemu...
>>
>>
>>
>> "Italo Gomes" <italogomes@ig.com.br> wrote in message
>> news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
>>> 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.
>>>
>>
>>
>
>


Teemu Keiski

8/3/2008 4:15:00 PM

0

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/ayy...

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...


"Italo Gomes" <italogomes@ig.com.br> wrote in message
news:e%23$rPzr5IHA.5052@TK2MSFTNGP03.phx.gbl...
>I have just found the GetStandardValues which may be what I was looking
>for... (at least I hope so) :-)
>
>
> "Italo Gomes" <italogomes@ig.com.br> wrote in message
> news:O7A0vcr5IHA.4776@TK2MSFTNGP05.phx.gbl...
>>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" <joteke@aspalliance.com> wrote in message
>> news:uj2N4Lr5IHA.1892@TK2MSFTNGP06.phx.gbl...
>>> 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(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
>>> AspInsider, ASP.NET MVP
>>> http://blogs.aspadvice....
>>> http://teemu...
>>>
>>>
>>>
>>> "Italo Gomes" <italogomes@ig.com.br> wrote in message
>>> news:%23v3ZcKq5IHA.3480@TK2MSFTNGP03.phx.gbl...
>>>> 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.
>>>>
>>>
>>>
>>
>>
>
>