Generic Composite control (or any web control)

Discussion in 'ASP .Net Building Controls' started by dave.dolan, Aug 23, 2006.

  1. dave.dolan

    dave.dolan Guest

    I'm building a Composite control to reflect on an object and build a widget
    for each of it's properties based on a custom set of attributes. I'm trying
    to do it as a generic, and it works to render the control, but it won't
    actually do anything when I try to access it... and infact, trying to access
    it kills the vshost process in the debugging, so something is obviously
    really wrong. (I've been all excited here becaue I'm using DynamicMethod to
    access the properties and populate the controls, but when I go to access it
    is the problem) Is it even possible to do Generic Webcontrols? I'm doing it
    like this: (like I said, compiles and renders, just on post back, it kills my
    server process)

    OnInit()
    {
    ObjectWidget<AddressObject> addressEditor = new
    ObjectWidget<AddressObject>();
    addressEditor.ID = "FooBar";
    Page.Form.Controls.Add(addressEditor);

    }

    Button1_OnClick(blah)
    {
    // tried using findcontrol, but returns null, when I list control types
    by enumerating them it actually shows one of the right type, at position 2
    so..
    //AddressObject ao = (Page.Form.FindControl("FooBar") as
    ObjectWidget<AddressObject>).Item;

    // yes I know not to do this in real life, I'm just trying to figure
    this out
    AddressObject ao = (Page.Form.Controls[2] as
    ObjectWidget<AddressObject>).Item;

    // the Item property is of Type T, in this case AddressObject


    // test
    Response.Write(ao.Street + "<br/>");
    Response.Write(ao.City + "<br/>");
    }

    Am I barking up the wrong tree? I can refactor it to take a property that
    contains a System.Type but I'd also have to have a method of it that returns
    a System.Object to access the internal value, which if you ask me is pretty
    yuk.
     
    dave.dolan, Aug 23, 2006
    #1
    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. sleigh
    Replies:
    1
    Views:
    2,741
    sleigh
    Feb 12, 2004
  2. ManicQin
    Replies:
    2
    Views:
    401
    Kai-Uwe Bux
    Jul 4, 2008
  3. ManicQin
    Replies:
    0
    Views:
    261
    ManicQin
    Jul 17, 2008
  4. Chad
    Replies:
    0
    Views:
    255
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    296
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page