【问题标题】:Diificulty in using Events and Delegates难以使用事件和委托
【发布时间】:2013-10-01 16:31:32
【问题描述】:

我试图从用户控件调用父页面中的方法:

用户控制:

    public delegate void CallParent();
    public event CallParent BindData;

   protected void LoadDataPageWise(int iCurrentPage)
        {
            iPageIndex1 = iCurrentPage - 1;
            BindData();           // This should trigger method in parent page
            DisplayPageNumber();
        }

父页面:

如何在父页面的页面加载中附加该委托?

   public void BindGridRecords()
        {
            grdPages.PageIndex = rptPager.iPageIndex1;
            grdPages.DataBind();
            Session["PageIndex"] = grdPages.PageIndex;
        }

【问题讨论】:

    标签: c# asp.net gridview user-controls delegates


    【解决方案1】:

    将此行添加到父页面的加载方法中:

    rptPager.BindData += this.BindGridRecords;

    【讨论】:

    • 假设 grdPages 是用户控件的名称。如果没有,请将用户控件的名称放在那里。
    【解决方案2】:

    我认为您可以在控件上使用this.Page。您可以将该属性转换为您的实际页面对象,然后在该对象上调用您想要的任何方法,只要它是可访问的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多