Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: reflection and events


Message #1 by "Christopher Duden" <christopher_duden@i...> on Fri, 4 Jan 2002 06:04:58
Situation:



I am loading one or more custom server controls and user controls from a

single page, the catch is which controls that load is determined at 

runtime.

I have the fully qualified type name as a string value available at 

runtime

for any given control that is loading and I can create the control as type

Control:



System.Web.UI.Control oCtrl = Page.LoadControl("apps\\" +

oSnapClassView[0]["codemanifestpath"].ToString().Trim());

Page.Controls.Add(oCtrl );



adding  it to the Pages control collection but I need to wire up a common

event that all these controls implement.



I was looking at Reflection and can find many examples of how to invoke a

method or property but none which cover using reflection with a loaded

control to wire up an event handler in a containing page.

Does anyone have any advice, code, examples etc they can help me out with?

Thanks



Message #2 by "Christopher Duden" <christopher_duden@i...> on Mon, 7 Jan 2002 17:00:02
I figured it out:



//get a type handle from a string

System.Type workingtype = System.Type.GetType(oSnapClassView[0]

["snapasptype"].ToString().Trim());

//load the control

System.Web.UI.Control oCon = Page.LoadControl("apps/" + oSnapClassView[0]

["codemanifestpath"].ToString().Trim());



//wire up SnapEvent Event to SnapCmdHandler

EventInfo menuevthandle = workingtype.GetEvent("SnapEvent");

menuevthandle.AddEventHandler(oCon, new SnapObjCmdHandler

(SnapCmdHandler));



Groovy huh?



CMD









> Situation:

> 

> I am loading one or more custom server controls and user controls from a

> single page, the catch is which controls that load is determined at 

> runtime.

> I have the fully qualified type name as a string value available at 

> runtime

> for any given control that is loading and I can create the control as 

type

> Control:

> 

> System.Web.UI.Control oCtrl = Page.LoadControl("apps\\" +

> oSnapClassView[0]["codemanifestpath"].ToString().Trim());

> Page.Controls.Add(oCtrl );

> 

> adding  it to the Pages control collection but I need to wire up a 

common

> event that all these controls implement.

> 

> I was looking at Reflection and can find many examples of how to invoke 

a

> method or property but none which cover using reflection with a loaded

> control to wire up an event handler in a containing page.

> Does anyone have any advice, code, examples etc they can help me out 

with?

> Thanks

> 


  Return to Index