我尝试执行以下操作:

        var userControl = UserControls.ProductDetailUserControl();
        userControl.ID = "id_SubProduct_"+productId;
        userControl.Visible = true;
        userControl.ValidationDependentOnControl = productOption.ClientID;
        userControl.ConditionallyVisible = productOption;
        plhDetails.Controls.Add(userControl);

抛出一个空异常

最佳答案

尝试这个

 var uProductDetails = (UserControls.ProductDetailUserControl)Page.LoadControl("UserControls/ProductDetailUserControl.ascx");

    //set properties
    plhDetails.Controls.Add(userControl);

10-06 05:10