【问题标题】:How to load user control at run time, in a aspx page?如何在运行时在 aspx 页面中加载用户控件?
【发布时间】:2012-06-25 19:28:44
【问题描述】:

我在某个 Control 文件夹中放置了 5 个用户控件,在运行时基于某个 ID 我想将用户控件从 Control 文件夹加载到 aspx 页面。 任何人都可以告诉我应该如何传递该 ID 来修复在运行时将哪个用户控件加载到某个 div 中。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    在页面初始化中做

    UserControl uc = new UserControl();
    string ID = "1";
    string userControl ="UC" + ID + ".ascx";
    uc = LoadControl(userControl) as UserControl;
    PlaceHolder1.Controls.Add(uc); //some place holder to place controls
    

    【讨论】:

    • 在一些下拉选择中,我正在加载特定的用户控件,但是我看到我通过上面的代码成功添加了用户控件,但是数据没有呈现到页面上,你能告诉我如何制作它。
    猜你喜欢
    • 2014-11-13
    • 2012-08-16
    • 2013-10-30
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多