Reputation: 22652
I have two usercontrols. One is loaded statically another dynamically.
In the aspx page I can write as follows for static user control.
ProgramAddSchedule.onNewProgram += new AddProgram.OnNewProgramClick(onNewProgram_btnHandler);
But dynamically loaded control’s event I am not able to get
Control myUserControl = (Control)Page.LoadControl("~/View/EditScheduleProgram.ascx");
How do I get the event of the dynamically loaded control?
Upvotes: 2
Views: 197
Reputation: 45083
Assuming the name of the type follows the name of the file, you can strongly-type it to that type, such that,
var myUserControl = Page.LoadControl("~/View/EditScheduleProgram.ascx") as EditScheduleProgram;
Then you have access to any custom (or specific) events exposed by that type but not by Control
, so,
myUserControl.MyEvent += MyEventHandler;
Upvotes: 2
Reputation: 23266
Cast to your Control Type
YourControlType myUserControl =(YourControlType)Page.LoadControl("~/View/EditScheduleProgram.ascx");
myUserControl.onNewProgram += new AddProgram.OnNewProgramClick(onNewProgram_btnHandler);
Upvotes: 2