小编use*_*996的帖子

LoadControl与构造ASP.Net控件

我有一个问题,为什么我们只能使用LoadControl添加动态控件.例如:

public partial class wucReportParam : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
          wucDate() ctrl = new wucDate();
          pnl.Controls.Add(ctrl);
    }
}
Run Code Online (Sandbox Code Playgroud)

在wucDate的page_load方法中,wucDate的子控件为null但是当我使用以下方法时:

   public partial class wucReportParam : System.Web.UI.UserControl
    {
        public Report Report;

        protected void Page_Load(object sender, EventArgs e)
        {
              ctrl = (wucDate)LoadControl(@"Reports\wucDate.ascx");
              pnl.Controls.Add(ctrl);
        }
    }
Run Code Online (Sandbox Code Playgroud)

在wucDate的page_load方法中,wucDate的子控件不为null.是否有人可以向我解释为什么当我使用contructor时,asp .net不会创建任何wucDate的子控件?谢谢

asp.net controls dynamic

9
推荐指数
1
解决办法
3733
查看次数

标签 统计

asp.net ×1

controls ×1

dynamic ×1