RT

解决方案 »

  1.   

    要导入的命名空间:using System.Reflection;
            用户控件:
            private void Button1_Click(object sender, System.EventArgs e)
            {
                //用反射方法动态调用父页面的方法
                System.Web.UI.Page p = this.Page;
                Type pageType = p.GetType();
                MethodInfo mi = pageType.GetMethod("SetLabel");
                mi.Invoke(p,new object[]{"aaa!"});
                
            } 
          父页面: 
           public void SetLabel(string str)
            {
                this.Label1.Text = str;;
            }   
      

  2.   

    在asp.net小项目中,最好不要使用反射,会降低性能.能避免最好.在用户控件中调用父页面的方法,不如在用户控件中,定义好一个供父页面调用的接口方法.
      

  3.   

    用户控件
    public event EventHandler ccc;需要调用父方法的地方使用
    if (ccc!= null)
    {
         ccc(this, EventArgs.Empty);
    }父页面
    PageLoad中
    UserControl1.ccc += new EventHandler(aaa);ccc事件
    protected void aaa(object sender, EventArgs e)
    {
    }