[英]UserControl doesn't appear on page if dynamically added in Page.Load
I have a custom ASP.NET user control that is added to a panel on a web page in the Page.Load method. 我有一个自定义ASP.NET用户控件,该控件在Page.Load方法中添加到网页的面板中。 The control contains some Labels and a GridView.
该控件包含一些标签和一个GridView。 I'm adding it to the page with this code:
我使用以下代码将其添加到页面中:
ReportingControl rc = new ReportingControl(this.Username, this.SoaContext, transactionId, p.PaymentTypeRequestKey);
this.pnlPB.Controls.Add(rc);
For some reason, the controls that are added aren't actually showing up on the page. 由于某些原因,添加的控件实际上未显示在页面上。 I also noticed that the controls within the control are all null but I don't know if that is part of the problem or if they are created at a later time.
我还注意到该控件内的所有控件均为空,但是我不知道这是否是问题的一部分,或者它们是否在以后创建。 Any ideas?
有任何想法吗?
Is it a UserControl
or a custom server control inheriting from CompositeControl
, WebControl
, etc.? 是从
CompositeControl
, WebControl
等继承的UserControl
还是自定义服务器控件?
Generally with user controls, you load them via the ascx location, such as: 通常,对于用户控件,您可以通过ascx位置加载它们,例如:
//load the control
Control rc= LoadControl("~/UserControls/MyControl.ascx");
//set up values as needed
rc.Username = this.Username;
//add the control where needed
this.pnlPB.Controls.Add(rc);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.