本文介绍了如何在用户控件中动态添加用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个用户控件,该控件将再次包含一个动态生成的用户控件,并且该控件可以相对于数据表中存在的数据重复N次。
I want to create a user control that will again contain a user control that will be dynamically generated and can be repeated N times with respect to data present in data table.
我该怎么做。
推荐答案
您要使用(Page,UserControl和MasterPage均从中继承)。您需要在Init事件期间执行此操作,以使回发内容正常工作。
You want to use TemplateControl.LoadControl (which both Page, UserControl and MasterPage inherit from). You need to do this during the Init event for postback stuff to work.
void Page_Init(Object Sender, EventArgs e) {
var control = LoadControl("Awesome.ascx");
// ... Magic!
}
这篇关于如何在用户控件中动态添加用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!