Object property binding

Discussion in 'ASP .Net Building Controls' started by Italo Gomes, Jul 15, 2008.

  1. Italo Gomes

    Italo Gomes Guest

    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, Jul 15, 2008
    #1
    1. Advertising

  2. Italo Gomes

    Teemu Keiski Guest

    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.com/joteke
    http://teemukeiski.net



    "Italo Gomes" <> wrote in message
    news:%...
    > 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, Jul 15, 2008
    #2
    1. Advertising

  3. Italo Gomes

    Teemu Keiski Guest

    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" <> wrote in message
    news:%...
    > 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, Jul 15, 2008
    #3
  4. Italo Gomes

    Italo Gomes Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    >> 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, Jul 15, 2008
    #4
  5. Italo Gomes

    Italo Gomes Guest

    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" <> wrote in message
    news:...
    > 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.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    > "Italo Gomes" <> wrote in message
    > news:%...
    >> 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, Jul 15, 2008
    #5
  6. Italo Gomes

    Italo Gomes Guest

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


    "Italo Gomes" <> wrote in message
    news:...
    >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" <> wrote in message
    > news:...
    >> 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.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >>
    >> "Italo Gomes" <> wrote in message
    >> news:%...
    >>> 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, Jul 15, 2008
    #6
  7. Italo Gomes

    Teemu Keiski Guest

    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" <> wrote in message
    news:e%23$...
    >I have just found the GetStandardValues which may be what I was looking
    >for... (at least I hope so) :)
    >
    >
    > "Italo Gomes" <> wrote in message
    > news:...
    >>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" <> wrote in message
    >> news:...
    >>> 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.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>>
    >>>
    >>> "Italo Gomes" <> wrote in message
    >>> news:%...
    >>>> 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, Aug 3, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,573
    Jordan
    Feb 10, 2004
  2. Eric Newton
    Replies:
    3
    Views:
    9,613
    Brock Allen
    Apr 4, 2005
  3. Amit
    Replies:
    6
    Views:
    13,922
    Assimalyst
    Oct 24, 2006
  4. TS
    Replies:
    3
    Views:
    2,514
  5. Replies:
    2
    Views:
    912
    Kevin Grover
    Oct 20, 2006
Loading...

Share This Page