首页 > 技术文章 > 使用C#反射实现用户控件调用父页面方法

qq1223558 2013-06-26 14:30 原文

using System.Reflection; 
MethodInfo mi =  this.Page.GetType().GetMethod("GetUserName"); //该处的GetUserName是父页面里的方法名称
        int userId=5;       
        return mi.Invoke(p, new object[] {userId}).ToString();  //userId指的指的是GetUserName所要传递的参数。

 

推荐阅读