L
Leszek Taratuta
Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEvent
event.
UserControl ctrl =
(UserControl)Page.LoadControl("~/MyApp/Controls/MenuBar.ascx");
// Get type information of the loaded user control.
Type myType = ctrl.GetType();
// Get SavePropertyEvent event using reflection.
EventInfo events = myType.GetEvent( "SavePropertyEvent" );
if ( events != null )
{
// Assign event handler (does not work).
// PROBLEM: The following line does not work because ctrl is of generic
UserControl type
// that does not define SavePropertyEvent event.
ctrl.SavePropertyEvent += new CommandEventHandler(
SavePropertyEvent_Raise );
// The following line could work, but C# does not provide such
construction:
// casting to variables of type Type. Should I use a Converter? How?
( (myType)ctrl ).SavePropertyEvent += new CommandEventHandler(
SavePropertyEvent_Raise );
}
The question is how to cast the 'ctrl' variable to the type assigned to
'myType' variable.
Any hints?
Thanks
Leszek Taratuta
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEvent
event.
UserControl ctrl =
(UserControl)Page.LoadControl("~/MyApp/Controls/MenuBar.ascx");
// Get type information of the loaded user control.
Type myType = ctrl.GetType();
// Get SavePropertyEvent event using reflection.
EventInfo events = myType.GetEvent( "SavePropertyEvent" );
if ( events != null )
{
// Assign event handler (does not work).
// PROBLEM: The following line does not work because ctrl is of generic
UserControl type
// that does not define SavePropertyEvent event.
ctrl.SavePropertyEvent += new CommandEventHandler(
SavePropertyEvent_Raise );
// The following line could work, but C# does not provide such
construction:
// casting to variables of type Type. Should I use a Converter? How?
( (myType)ctrl ).SavePropertyEvent += new CommandEventHandler(
SavePropertyEvent_Raise );
}
The question is how to cast the 'ctrl' variable to the type assigned to
'myType' variable.
Any hints?
Thanks
Leszek Taratuta