首页 > Web开发 > 详细

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

时间:2015-05-12 18:44:09      阅读:289      评论:0      收藏:0      [点我收藏+]

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

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 

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

原文:http://www.cnblogs.com/enamorbreeze/p/4498100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!