Let's say I have two webforms, A.aspx and B.aspx, where B.aspx contains some simple web controls such as a textbox and a button.
I'm trying to do the following:
When A.aspx is requested, I want to dynamically call and load B.aspx into memory and output details of all the controls contained in B.aspx.
Here is what I tried in the codebehind for A.aspx:
var compiledType = BuildManager.GetCompiledType("~/b.aspx");
if (compiledType != null)
{
var pageB = (Page)Activator.CreateInstance(compiledType);
}
foreach (var control in pageB.Controls)
{
//output some details for each control, like it's name and type...
}
When I try the code above, the controls collection for pageB is always empty.
Any ideas on how I can get this to work?
Some other important details:
- both webforms utilize a master page (so the web controls in b.aspx are actually placed within a "content" tag)
- I've also tried using BuildManager.CreateInstanceFromVirtualPath. No luck.