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));
posted @ 2010-10-05 11:31  大CC  阅读(1612)  评论(0编辑  收藏  举报
木书架 大CC的博客