Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEve nt
event.
UserControl ctrl =
(UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx");
// Get type information of the loaded user control.
Type myType = ctrl.GetType();
// Get SavePropertyEve nt event using reflection.
EventInfo events = myType.GetEvent ( "SavePropertyEv ent" );
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 SavePropertyEve nt event.
ctrl.SaveProper tyEvent += new CommandEventHan dler(
SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler(
SavePropertyEve nt_Raise );
}
The question is how to cast the 'ctrl' variable to the type assigned to
'myType' variable.
Any hints?
Thanks
Leszek Taratuta 8 1364
I'm a little confused. Is there a reason you can't use:
MenuBar mb = (MenuBar)Page.L oadControl(...) ;
mb.SaveProperty Event += new CommandEventHan dler(...);
--
Scott http://www.OdeToCode.com/blogs/scott/ Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEve nt event. UserControl ctrl = (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); // Get type information of the loaded user control. Type myType = ctrl.GetType();
// Get SavePropertyEve nt event using reflection. EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); 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 SavePropertyEve nt event. ctrl.SaveProper tyEvent += new CommandEventHan dler( SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( SavePropertyEve nt_Raise ); }
The question is how to cast the 'ctrl' variable to the type assigned to 'myType' variable.
Any hints? Thanks Leszek Taratuta
Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of them
define SavePropertyEve nt some not. The ASPX page need to assign event
handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as
UserControl, then discover the specific derived type that defines (or not)
SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message
news:53******** *************@m snews.microsoft .com... I'm a little confused. Is there a reason you can't use:
MenuBar mb = (MenuBar)Page.L oadControl(...) ; mb.SaveProperty Event += new CommandEventHan dler(...);
-- Scott http://www.OdeToCode.com/blogs/scott/
Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEve nt event. UserControl ctrl = (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); // Get type information of the loaded user control. Type myType = ctrl.GetType();
// Get SavePropertyEve nt event using reflection. EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); 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 SavePropertyEve nt event. ctrl.SaveProper tyEvent += new CommandEventHan dler( SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( SavePropertyEve nt_Raise ); }
The question is how to cast the 'ctrl' variable to the type assigned to 'myType' variable.
Any hints? Thanks Leszek Taratuta
You will look at the user control and see if it implements the
ISavePropertyEv ent interface, if it does, you will cast the generic
UserControl to a ISavePropertyEv ent to get the event to wire to.
I am not actually sure if this would work, but it compiled, but I didn't
actually run it.
<snippets>
public interace ISavePropertyEv ent
{
event CommandEventHan dler SavePropertyEve nt;
}
public myUserControl : UserControl : ISavePropertyEv ent
{
public event CommandEventHan dler SavePropertyEve nt;
}
UserControl control = Page.FindContro l( "myControlN ame" );
if ( control is ISavePropertyEv ent )
{
( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new
CommandEventHan dler(...)
}
HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message
news:OR******** ******@TK2MSFTN GP14.phx.gbl... Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of them define SavePropertyEve nt some not. The ASPX page need to assign event handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as UserControl, then discover the specific derived type that defines (or not) SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:53******** *************@m snews.microsoft .com... I'm a little confused. Is there a reason you can't use:
MenuBar mb = (MenuBar)Page.L oadControl(...) ; mb.SaveProperty Event += new CommandEventHan dler(...);
-- Scott http://www.OdeToCode.com/blogs/scott/
Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEve nt event. UserControl ctrl = (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); // Get type information of the loaded user control. Type myType = ctrl.GetType();
// Get SavePropertyEve nt event using reflection. EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); 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 SavePropertyEve nt event. ctrl.SaveProper tyEvent += new CommandEventHan dler( SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( SavePropertyEve nt_Raise ); }
The question is how to cast the 'ctrl' variable to the type assigned to 'myType' variable.
Any hints? Thanks Leszek Taratuta
Thanks.
I figured out this solution as well. The problem is that my user controls
can implement many different events. I just gave an example of
SavePropertyEve nt, but there may be many other: LoadControlEven t,
ChangeIdEvent, RefreshParentEv ent etc. It means I would need to create a
separate interface for each of those events:
ILoadControlEve nt, IChangeIdEvent, IRefreshParentE vent etc
I hoped there would be a more generic way to discover the type of user
control (using reflection or descriptors) in run-time and assign proper
event handlers.
For now it seems there is no generic way.
Thanks anyway,
Leszek
"William F. Robertson, Jr." <th****@nameht. org> wrote in message
news:Oy******** ******@TK2MSFTN GP10.phx.gbl... You will look at the user control and see if it implements the ISavePropertyEv ent interface, if it does, you will cast the generic UserControl to a ISavePropertyEv ent to get the event to wire to.
I am not actually sure if this would work, but it compiled, but I didn't actually run it.
<snippets> public interace ISavePropertyEv ent { event CommandEventHan dler SavePropertyEve nt; }
public myUserControl : UserControl : ISavePropertyEv ent { public event CommandEventHan dler SavePropertyEve nt; }
UserControl control = Page.FindContro l( "myControlN ame" ); if ( control is ISavePropertyEv ent ) { ( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new CommandEventHan dler(...) }
HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message news:OR******** ******@TK2MSFTN GP14.phx.gbl... Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of
them define SavePropertyEve nt some not. The ASPX page need to assign event handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as UserControl, then discover the specific derived type that defines (or
not) SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:53******** *************@m snews.microsoft .com... I'm a little confused. Is there a reason you can't use:
MenuBar mb = (MenuBar)Page.L oadControl(...) ; mb.SaveProperty Event += new CommandEventHan dler(...);
-- Scott http://www.OdeToCode.com/blogs/scott/
> Hello, > > I have the following code: > > // Load the MenuBar.ascx user control. The control defines > SavePropertyEve nt > event. > UserControl ctrl = > (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); > // Get type information of the loaded user control. Type myType = > ctrl.GetType(); > > // Get SavePropertyEve nt event using reflection. > EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); > 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 SavePropertyEve nt event. > ctrl.SaveProper tyEvent += new CommandEventHan dler( > SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( > SavePropertyEve nt_Raise ); > } > > The question is how to cast the 'ctrl' variable to the type assigned > to 'myType' variable. > > Any hints? > Thanks > Leszek Taratuta >
Ahh, I went back and reread your first post. Sorry for the confusion; I am
not convinced this is the best approach for you to take, but here is how to
do it.
You were almost there for your syntax.
<snippet>
if ( events != null )
events.AddEvent Handler( ctrl, new CommandEventHan dler(
SavePropertyEve nt_Raise ) );
This will add the event handler to your control.
HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message
news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Thanks. I figured out this solution as well. The problem is that my user controls can implement many different events. I just gave an example of SavePropertyEve nt, but there may be many other: LoadControlEven t, ChangeIdEvent, RefreshParentEv ent etc. It means I would need to create a separate interface for each of those events: ILoadControlEve nt, IChangeIdEvent, IRefreshParentE vent etc
I hoped there would be a more generic way to discover the type of user control (using reflection or descriptors) in run-time and assign proper event handlers.
For now it seems there is no generic way.
Thanks anyway, Leszek
"William F. Robertson, Jr." <th****@nameht. org> wrote in message news:Oy******** ******@TK2MSFTN GP10.phx.gbl... You will look at the user control and see if it implements the ISavePropertyEv ent interface, if it does, you will cast the generic UserControl to a ISavePropertyEv ent to get the event to wire to.
I am not actually sure if this would work, but it compiled, but I didn't actually run it.
<snippets> public interace ISavePropertyEv ent { event CommandEventHan dler SavePropertyEve nt; }
public myUserControl : UserControl : ISavePropertyEv ent { public event CommandEventHan dler SavePropertyEve nt; }
UserControl control = Page.FindContro l( "myControlN ame" ); if ( control is ISavePropertyEv ent ) { ( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new CommandEventHan dler(...) }
HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message news:OR******** ******@TK2MSFTN GP14.phx.gbl... Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of them define SavePropertyEve nt some not. The ASPX page need to assign event handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as UserControl, then discover the specific derived type that defines (or not) SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:53******** *************@m snews.microsoft .com... > I'm a little confused. Is there a reason you can't use: > > MenuBar mb = (MenuBar)Page.L oadControl(...) ; > mb.SaveProperty Event += new CommandEventHan dler(...); > > -- > Scott > http://www.OdeToCode.com/blogs/scott/ > > > Hello, > > > > I have the following code: > > > > // Load the MenuBar.ascx user control. The control defines > > SavePropertyEve nt > > event. > > UserControl ctrl = > > (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); > > // Get type information of the loaded user control. Type myType = > > ctrl.GetType(); > > > > // Get SavePropertyEve nt event using reflection. > > EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); > > 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 SavePropertyEve nt event. > > ctrl.SaveProper tyEvent += new CommandEventHan dler( > > SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( > > SavePropertyEve nt_Raise ); > > } > > > > The question is how to cast the 'ctrl' variable to the type
assigned > > to 'myType' variable. > > > > Any hints? > > Thanks > > Leszek Taratuta > > > >
Ah, I can see now what you need to do. I'm sure this can be done with reflection
- ASP.NET runtime does it all the time. Have you made any progress?
--
Scott http://www.OdeToCode.com/blogs/scott/ Thanks. I figured out this solution as well. The problem is that my user controls can implement many different events. I just gave an example of SavePropertyEve nt, but there may be many other: LoadControlEven t, ChangeIdEvent, RefreshParentEv ent etc. It means I would need to create a separate interface for each of those events: ILoadControlEve nt, IChangeIdEvent, IRefreshParentE vent etc I hoped there would be a more generic way to discover the type of user control (using reflection or descriptors) in run-time and assign proper event handlers.
For now it seems there is no generic way.
Thanks anyway, Leszek "William F. Robertson, Jr." <th****@nameht. org> wrote in message news:Oy******** ******@TK2MSFTN GP10.phx.gbl...
You will look at the user control and see if it implements the ISavePropertyEv ent interface, if it does, you will cast the generic UserControl to a ISavePropertyEv ent to get the event to wire to.
I am not actually sure if this would work, but it compiled, but I didn't actually run it.
<snippets> public interace ISavePropertyEv ent { event CommandEventHan dler SavePropertyEve nt; } public myUserControl : UserControl : ISavePropertyEv ent { public event CommandEventHan dler SavePropertyEve nt; } UserControl control = Page.FindContro l( "myControlN ame" ); if ( control is ISavePropertyEv ent ) { ( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new CommandEventHan dler(...) } HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message news:OR******** ******@TK2MSFTN GP14.phx.gbl...
Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of them define SavePropertyEve nt some not. The ASPX page need to assign event handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as UserControl, then discover the specific derived type that defines (or not) SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:53******** *************@m snews.microsoft .com...
I'm a little confused. Is there a reason you can't use:
MenuBar mb = (MenuBar)Page.L oadControl(...) ; mb.SaveProperty Event += new CommandEventHan dler(...); -- Scott http://www.OdeToCode.com/blogs/scott/ > Hello, > > I have the following code: > > // Load the MenuBar.ascx user control. The control defines > SavePropertyEve nt > event. > UserControl ctrl = > (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); > // Get type information of the loaded user control. Type myType = > ctrl.GetType(); > // Get SavePropertyEve nt event using reflection. > EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); > 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 SavePropertyEve nt event. > ctrl.SaveProper tyEvent += new CommandEventHan dler( > SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( > SavePropertyEve nt_Raise ); > } > The question is how to cast the 'ctrl' variable to the type > assigned to 'myType' variable. > > Any hints? > Thanks > Leszek Taratuta
This is a part of a real project with a deadline, so I had to move on with
other things.
Temporarily I just duplicated some code, without using reflection.
Thanks,
Leszek
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message
news:54******** *************@m snews.microsoft .com... Ah, I can see now what you need to do. I'm sure this can be done with
reflection - ASP.NET runtime does it all the time. Have you made any progress?
-- Scott http://www.OdeToCode.com/blogs/scott/
Thanks. I figured out this solution as well. The problem is that my user controls can implement many different events. I just gave an example of SavePropertyEve nt, but there may be many other: LoadControlEven t, ChangeIdEvent, RefreshParentEv ent etc. It means I would need to create a separate interface for each of those events: ILoadControlEve nt, IChangeIdEvent, IRefreshParentE vent etc I hoped there would be a more generic way to discover the type of user control (using reflection or descriptors) in run-time and assign proper event handlers.
For now it seems there is no generic way.
Thanks anyway, Leszek "William F. Robertson, Jr." <th****@nameht. org> wrote in message news:Oy******** ******@TK2MSFTN GP10.phx.gbl...
You will look at the user control and see if it implements the ISavePropertyEv ent interface, if it does, you will cast the generic UserControl to a ISavePropertyEv ent to get the event to wire to.
I am not actually sure if this would work, but it compiled, but I didn't actually run it.
<snippets> public interace ISavePropertyEv ent { event CommandEventHan dler SavePropertyEve nt; } public myUserControl : UserControl : ISavePropertyEv ent { public event CommandEventHan dler SavePropertyEve nt; } UserControl control = Page.FindContro l( "myControlN ame" ); if ( control is ISavePropertyEv ent ) { ( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new CommandEventHan dler(...) } HTH,
bill
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message news:OR******** ******@TK2MSFTN GP14.phx.gbl...
Sorry for confusion. I have sent just a part of code.
Actually I need to load many user controls of diffrent types. Some of them
define SavePropertyEve nt some not. The ASPX page need to assign event handler for those user controls that define SavePropertyEve nt.
I wanted to create a generic code that would load user controls as UserControl, then discover the specific derived type that defines (or not)
SavePropertyEve nt, and assign event handler to this event.
Thanks for reply anyway.
Any other suggestions?
Leszek Taratuta
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:53******** *************@m snews.microsoft .com...
> I'm a little confused. Is there a reason you can't use: > > MenuBar mb = (MenuBar)Page.L oadControl(...) ; > mb.SaveProperty Event += new CommandEventHan dler(...); > -- > Scott > http://www.OdeToCode.com/blogs/scott/ >> Hello, >> >> I have the following code: >> >> // Load the MenuBar.ascx user control. The control defines >> SavePropertyEve nt >> event. >> UserControl ctrl = >> (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); >> // Get type information of the loaded user control. Type myType = >> ctrl.GetType(); >> // Get SavePropertyEve nt event using reflection. >> EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); >> 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 SavePropertyEve nt event. >> ctrl.SaveProper tyEvent += new CommandEventHan dler( >> SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( >> SavePropertyEve nt_Raise ); >> } >> The question is how to cast the 'ctrl' variable to the type >> assigned to 'myType' variable. >> >> Any hints? >> Thanks >> Leszek Taratuta
Did you see the reflection code to accomplish what you wanting to
accomplish?
bill
UserControl ctrl =
(UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx");
// Get type information of the loaded user control.
Type myType = ctrl.GetType();
// Get SavePropertyEve nt event using reflection.
EventInfo events = myType.GetEvent ( "SavePropertyEv ent" );
if ( events != null )
{
//this is how to dynamically add events using reflection.
events.AddEvent Handler( ctrl, new CommandEventHan dler(
SavePropertyEve nt_Raise ) );
}
"Leszek Taratuta" <ad*@taratuta.n et> wrote in message
news:OP******** ******@TK2MSFTN GP11.phx.gbl... This is a part of a real project with a deadline, so I had to move on with other things. Temporarily I just duplicated some code, without using reflection.
Thanks, Leszek
"Scott Allen" <sc***@nospam.O deToCode.com> wrote in message news:54******** *************@m snews.microsoft .com... Ah, I can see now what you need to do. I'm sure this can be done with reflection - ASP.NET runtime does it all the time. Have you made any progress?
-- Scott http://www.OdeToCode.com/blogs/scott/
Thanks. I figured out this solution as well. The problem is that my user controls can implement many different events. I just gave an example of SavePropertyEve nt, but there may be many other: LoadControlEven t, ChangeIdEvent, RefreshParentEv ent etc. It means I would need to create a separate interface for each of those events: ILoadControlEve nt, IChangeIdEvent, IRefreshParentE vent etc I hoped there would be a more generic way to discover the type of user control (using reflection or descriptors) in run-time and assign proper event handlers.
For now it seems there is no generic way.
Thanks anyway, Leszek "William F. Robertson, Jr." <th****@nameht. org> wrote in message news:Oy******** ******@TK2MSFTN GP10.phx.gbl...
> You will look at the user control and see if it implements the > ISavePropertyEv ent interface, if it does, you will cast the generic > UserControl to a ISavePropertyEv ent to get the event to wire to. > > I am not actually sure if this would work, but it compiled, but I > didn't actually run it. > > <snippets> > public interace ISavePropertyEv ent > { > event CommandEventHan dler SavePropertyEve nt; > } > public myUserControl : UserControl : ISavePropertyEv ent > { > public event CommandEventHan dler SavePropertyEve nt; > } > UserControl control = Page.FindContro l( "myControlN ame" ); > if ( control is ISavePropertyEv ent ) > { > ( ( ISavePropertyEv ent ) control).SavePr opertyEvent += new > CommandEventHan dler(...) > } > HTH, > > bill > > "Leszek Taratuta" <ad*@taratuta.n et> wrote in message > news:OR******** ******@TK2MSFTN GP14.phx.gbl... > >> Sorry for confusion. I have sent just a part of code. >> >> Actually I need to load many user controls of diffrent types. Some >> of >> them
>> define SavePropertyEve nt some not. The ASPX page need to assign >> event handler for those user controls that define SavePropertyEve nt. >> >> I wanted to create a generic code that would load user controls as >> UserControl, then discover the specific derived type that defines >> (or >> not)
>> SavePropertyEve nt, and assign event handler to this event. >> >> Thanks for reply anyway. >> >> Any other suggestions? >> >> Leszek Taratuta >> >> "Scott Allen" <sc***@nospam.O deToCode.com> wrote in message >> news:53******** *************@m snews.microsoft .com... >> >>> I'm a little confused. Is there a reason you can't use: >>> >>> MenuBar mb = (MenuBar)Page.L oadControl(...) ; >>> mb.SaveProperty Event += new CommandEventHan dler(...); >>> -- >>> Scott >>> http://www.OdeToCode.com/blogs/scott/ >>>> Hello, >>>> >>>> I have the following code: >>>> >>>> // Load the MenuBar.ascx user control. The control defines >>>> SavePropertyEve nt >>>> event. >>>> UserControl ctrl = >>>> (UserControl)Pa ge.LoadControl( "~/MyApp/Controls/MenuBar.ascx"); >>>> // Get type information of the loaded user control. Type myType = >>>> ctrl.GetType(); >>>> // Get SavePropertyEve nt event using reflection. >>>> EventInfo events = myType.GetEvent ( "SavePropertyEv ent" ); >>>> 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 SavePropertyEve nt event. >>>> ctrl.SaveProper tyEvent += new CommandEventHan dler( >>>> SavePropertyEve nt_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 ).SavePropertyE vent += new CommandEventHan dler( >>>> SavePropertyEve nt_Raise ); >>>> } >>>> The question is how to cast the 'ctrl' variable to the type >>>> assigned to 'myType' variable. >>>> >>>> Any hints? >>>> Thanks >>>> Leszek Taratuta
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Emma |
last post by:
Hi,
I'm developing a GUI with almost all Usercontrols. It's been working
wonderfull up till a few weeks ago, and really crashed yesterday.
Suddenly I can no longer add some of my usercontrols to any of the others
(I've also tried to create new usercontrols and windowforms and add them to
the new control, but that doesn't work any better). It's really frustrating
since I've been able to add them and run the program before.
|
by: Anders K. Jacobsen [DK] |
last post by:
Hi
I have some common UserControls i want to share between to sites (on the
same mashine but on diffrent virtual paths).
right now i have on solution file with aprox 10 projects. 2 of these is
webprojetcs wich need to shere some common userControls. Optimally i want a
class libarary project wich contains the controls so i could import the DLL
and use the controls. But that of course doesnt work.
|
by: Alixx Skevington |
last post by:
Hi there peeps,
I am having a problem have just started to use usercontrols, and I am
hitting a problem.
I get the error message above, now each control has a table, and 1
asp:textbox control. Now when I first got this error I just put the form
tags around the table in the control with the runat=server set. But however
I get the following error if i do that too the other controls.
|
by: Søren M. Olesen |
last post by:
Hi
I starting to get the following compiler error, but I really don't know how
to resolve it.
Value of type 'DXP.Shared.myPath' cannot be converted to
'DXP.Shared.myPath'. Type mismatch could be due to the mixing of a file
reference with a project reference to assembly 'DXP.Shared'. Try replacing
the file reference to 'DXP.Shared.dll' in project '2_App_Code' with a
|
by: Søren M. Olesen |
last post by:
Hi
In my website I have a module, placed under App_Code with a number of
utility functions. For one of these functions I'm trying to pass a
usercontrol as an argument, however I keep getting 'Type myControl is not
defined' ... how come??, and how do I solve it??
Under App_Code:
| |
by: Carlo Razzeto |
last post by:
Hey, I've got a couple of production UserControls going in my companies web
system, but I'm having a couple of annoying issues with them. One of them,
for instance is a ScannerButton control which launches an in house scanning
application from a web page. When vs.net 2005 add the variable to the
..aspx.desginer.vb file it adds it as System.Web.UserControl rather than
WebAppNameSpace.ScannerButton which is what the object actually is. Is...
|
by: daniel.hedz |
last post by:
I am generating a usercontrol dynamically successfully, but when I try
to find that usercontrol I get a type mismatch. This is what I am
doing:
//Loading my usercontrol
MyWebApp.Folder.Folder.MyUsercontrol myUC =
(MyWebApp.Folder.Folder.MyUsercontrol)
LoadControl("~/Folder/Folder/MyUsercontrol.ascx");
|
by: Nathan Sokalski |
last post by:
In several of my UserControls I add properties. If I access these properties
in the CodeBehind of the pages that use the controls, I recieve an error
when compiling. The reason for this is because the compiler tries to compile
the pages that use the UserControls before compiling the UserControls, and
therefore does not know that the property exists when compiling. The only
way around this that I have found is to use the CType() function as...
|
by: John A Grandy |
last post by:
I'm in a vigorous debate at my work regarding objects assuming knowledge of
the type their containing object.
This debate pertains specifically to ASP.NET, but I have decided to post in
the C# forum because this is where most of the OO gurus hang out, and I view
this as a fundamental issue of OO design.
In ASP.NET, objects of type WebForm and UserControl have an intrinsic Page
property which refers to their containing Page.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |