• 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 

  • 相关阅读:
    Python shutil模块
    Flask 上传文件
    Flask DBUtils
    flash-session
    Flash 上下文管理
    python 栈
    python 偏函数
    threding.local
    next() 与 nextLine() 区别
    Thread.sleep(1000*3); // 休眠3秒
  • 原文地址:https://www.cnblogs.com/enamorbreeze/p/4498100.html
Copyright © 2020-2023  润新知