Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Wiring an Event from a control up to a page event handler


Message #1 by "Christopher Duden" <christopher_duden@i...> on Mon, 7 Jan 2002 17:13:00
I am attempting to wire up an event up that is declared in a control to a 

handler in a page.  I know I can use Event Bubbling but I would like to 

do something more specific.  I am using reflection to do this, I don't 

know what the control will be at compile time, only at runtime.  I do 

know however that the control will declare this event.



Here is what I have:



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

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



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

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



MethodInfo portalcmdhandle = workingtype.GetMethod("PortalCmdHandler");





What I can't figure out is how to bind this handle to the event back to 

the control I have loaded (oCon).  I have tried various things -- no 

glory.



This:



this.PortalEvent += (PortalCmdHandler)Delegate.CreateDelegate(typeof

(METADB_PORTAL.SnapObjCmdHandler),oCon,portalcmdhandle.Name);



fails with the error:

Description: An unhandled exception occurred during the execution of the 

current web request. Please review the stack trace for more information 

about the error and where it originated in the code. 



Exception Details: System.ArgumentException: Error binding to target 

method.





Anyone have any ideas?

I realize it is probably something simple but....



CMD
Message #2 by "Christopher Duden" <christopher_duden@i...> on Thu, 10 Jan 2002 00:13:12
This should read:



I am attempting to wire up an event that is declared in the page

to a handler declared in a control at runtime....



Sorry about the mistake.



CMD



> I am attempting to wire up an event up that is declared in a control to 

a 

> handler in a page.  I know I can use Event Bubbling but I would like to 

> do something more specific.  I am using reflection to do this, I don't 

> know what the control will be at compile time, only at runtime.  I do 

> know however that the control will declare this event.

> 

> Here is what I have:

> 

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

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

> 

> System.Web.UI.Control oCon = Page.LoadControl("apps/" + oSnapClassView

[0]

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

> 

> MethodInfo portalcmdhandle = workingtype.GetMethod("PortalCmdHandler");

> 

> 

> What I can't figure out is how to bind this handle to the event back to 

> the control I have loaded (oCon).  I have tried various things -- no 

> glory.

> 

> This:

> 

> this.PortalEvent += (PortalCmdHandler)Delegate.CreateDelegate(typeof

> (METADB_PORTAL.SnapObjCmdHandler),oCon,portalcmdhandle.Name);

> 

> fails with the error:

> Description: An unhandled exception occurred during the execution of 

the 

> current web request. Please review the stack trace for more information 

> about the error and where it originated in the code. 

> 

> Exception Details: System.ArgumentException: Error binding to target 

> method.

> 

> 

> Anyone have any ideas?

> I realize it is probably something simple but....

> 

> CMD

  Return to Index