ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用

在用户控件中,获取父页面的方法

1:方法没有参数(userInfor())

string userInfor = Convert.ToString(this.Page.GetType().GetMethod("userInfor").Invoke(this.Page, null));    //获取到的值是object类型

2: 方法有参数(userInfor(int a,string b))

string userInfor = Convert.ToString(this.Page.GetType().GetMethod("userInfor").Invoke(this.Page, new object[] { "参数1","参数2" }));

 

用户控件与用户控件之间调用:

//获得父页面
Page p = this.Parent.Page;
 //获得父页面的子控件 
UserControl uc = p.FindControl("tj_ReceiptList2") as UserControl;
Type pageType = uc.GetType();
//父类方法名
MethodInfo mi = pageType.GetMethod("Loading");
//参数
mi.Invoke(uc, new object[] { "参数1", "参数2" });

 

注意:
    被调用父页或其他用户控件的方法必须是public!

转载博文:http://www.cnblogs.com/over140/archive/2008/06/16/1222908.html 

posted on 2015-05-12 17:56  改变从今天开始  阅读(186)  评论(0编辑  收藏  举报

导航