如何在运行时加载用户控件,在aspx页面?

时间:2012-06-25 10:56:59

标签: c# asp.net

我在一些Control文件夹中放置了5个用户控件,在运行时基于某些ID,我想将用户控件从Control文件夹加载到aspx页面。 任何正文都可以告诉我应该如何传递该ID来修复在运行时在某个div中加载哪个用户控件。

1 个答案:

答案 0 :(得分:4)

在Page Init中

UserControl uc = new UserControl();
string ID = "1";
string userControl ="UC" + ID + ".ascx";
uc = LoadControl(userControl) as UserControl;
PlaceHolder1.Controls.Add(uc); //some place holder to place controls