我有一个问题,为什么我们只能使用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的子控件?谢谢