我使用BuildManager类来加载动态生成的ASPX文件,请注意它没有相应的.cs文件.
使用以下代码我能够加载aspx文件,我甚至可以遍历动态创建的aspx文件的控件集合,但是当我为控件分配值时,它们没有显示出来.例如,如果我将值"Dummy"绑定到aspx页面的TextBox控件,则文本框保持为空.
这是我正在使用的代码
protected void Page_Load(object sender, EventArgs e)
{
LoadPage("~/Demo.aspx");
}
public static void LoadPage(string pagePath)
{
// get the compiled type of referenced path
Type type = BuildManager.GetCompiledType(pagePath);
// if type is null, could not determine page type
if (type == null)
throw new ApplicationException("Page " + pagePath + " not found");
// cast page object (could also cast an interface instance as well)
// in this example, ASP220Page is a custom base page
System.Web.UI.Page pageView = (System.Web.UI.Page)Activator.CreateInstance(type); …