简体   繁体   English

如果动态添加到Page.Load中,则UserControl不会出现在页面上

[英]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.? 是从CompositeControlWebControl等继承的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.

相关问题 c# - 如果我在代码中动态添加了一些控件,则UserControl不会出现在winform上 - c# - UserControl doesn't appear on winform if i dynamically added some controls in the code 如果要处理按钮点击事件,则在Page.Load期间识别 - Identify during Page.Load if Button click event is going to be handled 带按钮的用户控件 - 当 uc 动态添加到另一个页面时 - Usercontrol with button - When uc is added dynamically to another page 如何将控件移动到页面中动态添加的用户控件中? - How can I move controls into a dynamically added usercontrol into page? 使用LoadControl + UserControl时,Asp.net图表在Page_Load中不起作用 - Asp.net Chart doesn't work in Page_Load when using LoadControl + UserControl 隐藏在Page_Load上的弹出式聊天框,是否不会再次出现在另一页的PageInit上? - Hiding a popup Chat box on Page_Load, Doesn't re-appear on PageInit of another page? 如何在页面上动态管理UserControl…? - how to Manage UserControl dynamically on a page…? 动态添加的页脚不会停留在页面底部 ASP.NET - Dynamically added footer doesn't stay at the bottom of page ASP.NET Page_Load没有在UserControl中触发 - Page_Load not firing in UserControl 自定义通用用户控件未出现在工具箱中 - Custom Generic UserControl doesn't appear in Toolbox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM