LoadControl vs Construct ASP.Net Control

后端 未结 2 2139
一生所求
一生所求 2021-02-14 19:41

I have a question why we can only add dynamic control using LoadControl. For example:

public partial class wucReportParam : System.Web.UI.UserControl
{
    prote         


        
2条回答
  •  孤街浪徒
    2021-02-14 20:07

    Apparently, using LoadControl with typeof (or GetType) has the same problem as using 'new' where the child controls are not initialized. Using LoadControl with a string to the ASCX file works.

    Does not initialize child controls.

    LoadControl(typeof(MyReport), null);
    

    Works!

    LoadControl("Report.ascx");
    

提交回复
热议问题