I have a problem similar to Calling a method in parent page from user control, except that my user control is dynamically generated at page creation.
I tried the preferred solution in the answer above, but since I don’t know in advance how many copies of the control will be required on the page, I can’t subscribe to the event on Page_Load.
This application needs a major overhaul in its logic, but it’s out of scope for my current project.
I’ve currently implemented the less preferred ((MyPageName)this.Page).CustomMethod();
, but would like to do it the “right” way if I can.
Do you have any suggestions?
EDIT: The code for the control is in a page separate from the page. (I intend to reuse it elsewhere in the project.) This means the control doesn't know what handlers are available on the page.