aspx页面动态加载ascx用户控件

1、无方式的调用

Control a = Page.LoadControl("0.ascx");
a.ID = "A0";
Controls.Add(a);

2、调用控件,并引用控件中方法函数

Control uc = Page.LoadControl("0.ascx"); //控件
Type tc = uc.GetType();  
System.Reflection.MethodInfo t = tc.GetMethod("tt"); //tt为控件中函数
Response.Write(t.Invoke(uc,null));

2、调用控件,并引用控件中方法函数,函数有参数

Control uc = Page.LoadControl("0.ascx"); //控件
Type tc = uc.GetType();  
System.Reflection.MethodInfo m = tc.GetMethod("xx"); //xx为控件中函数
object[] bjParas = new object[1]; 
bjParas[0] = 1;//控件中函数参数
Response.Write(m.Invoke(uc, bjParas));
原文地址:https://www.cnblogs.com/me115/p/1843557.html