用户控件调用父页面方法

来源:互联网 发布:java 字符串转json对象 编辑:程序博客网 时间:2024/05/07 17:35

1.反射

            //用反射方法动态调用父页面的方法
            System.Web.UI.Page p = this.Page;
            Type pageType = p.GetType();
            MethodInfo mi = pageType.GetMethod("TestMethod");
            mi.Invoke(p, new object[] { "test" });

2.this.Page转换

WebForm1   form   =   (WebForm1)this.Page;

 

3.接口

在控件中暴露一个Father的属性

        protected void Page_Init(object sender, EventArgs e)
        {
            Share_budgetchargetype1.Father = this;
            Share_engineer1.Father = this;
        }

原创粉丝点击