LoadControl vs Construct ASP.Net Control

后端 未结 3 828
Happy的楠姐
Happy的楠姐 2021-02-14 19:50

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

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


        
3条回答
  •  心在旅途
    2021-02-14 20:16

    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");
    

提交回复
热议问题