小编San*_*rst的帖子

使用Build Manager类加载ASPX文件并填充其控件

我使用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); …

c# asp.net webforms dynamic

6
推荐指数
1
解决办法
2307
查看次数

标签 统计

asp.net ×1

c# ×1

dynamic ×1

webforms ×1