At runtime, is it possible to discover programmatically which events are exposed by a user control (.ascx) and subscribe to them in some generic fashion?
What I am wanting to accomplish is to read in settings from a "layout" file which tells me which .ascx controls to load into memory (and display on the form). I can get that to work, but then I don't know how to subscribe to the events of these controls, since I am dealing with them as a collection of generic "controls" vs a collection of different control types.
So the process would be something like this:
-read in the file
-run "LoadControl" for each control name listed in the file
-subscribe to any public events the control emits
-provide some sort of central processing for the events (yet to be determined).
Is this making any sense?
public partial class SiteManager : System.Web.UI.Page
protected void Page_PreInit(object sender, System.EventArgs e)
this.MasterPageFile = "~/contentfiles/" + Page.StyleSheetTheme + "/TCSSite.Master";
protected void Page_Load(object sender, EventArgs e)
string layout = "";
if (Request.QueryString["layout"] != null)
layout = Request.QueryString["layout"] as string;
layout = "default";
private void DisplayLayout(string layout)
StreamReader sr = new StreamReader(Server.MapPath("~/CustomLayouts/") + Page.StyleSheetTheme + "/" + layout + ".xml");
string filecontents = sr.ReadToEnd();
string countstr = GlobalMethods.ExtractValueFromXML(filecontents, "<count>");
int count = Convert.ToInt32(countstr);
string tempGUID = "";
string settings = "";
string settingsarray = new string[count];
for (int i = 1; i <= count; i++)
settings = GlobalMethods.ExtractValueFromXML(filecontents, "<" + i.ToString() + ">");
settingsarray = settings.Split(',');
Control c = LoadControl("~/UserControls/" + settingsarray + ".ascx");
c.Visible = true;
tempGUID = Guid.NewGuid().ToString();
c.ID = settingsarray + tempGUID + i.ToString();
foreach (Control c in GlobalMethods.divlayoutgencontrols)
the layout file: