Generic Composite control (or any web control)

D

dave.dolan

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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top