Monday, 23 April 2012

Firing Events of User Control from Parent Page

// Pager1  User Control  i.e pager.ascx

    public event EventHandler UserControlNextButtonClicked;   // Events Declarations
    public event EventHandler UserControlPreviousButtonClicked;



    private void OnUserControlNextButtonClick()
    {
        if (UserControlNextButtonClicked != null)
        {
            UserControlNextButtonClicked(this, EventArgs.Empty);
        }
    }

    private void OnUserControlPreviousButtonClick()
    {
        if (UserControlPreviousButtonClicked != null)
        {
            UserControlPreviousButtonClicked(this, EventArgs.Empty);
        }
    }

    protected void lnk_Previous_Click(object sender, EventArgs e)
    {
        OnUserControlPreviousButtonClick();
    }
    protected void lnk_Next_Click(object sender, EventArgs e)
    {
        OnUserControlNextButtonClick();
    }

-------------------------------------------------------
aspx.cs

//Page Load
   protected void Page_Load(object sender, EventArgs e)
    {
 Pager1.UserControlNextButtonClicked += new EventHandler(Pager1_UserControlNextButtonClicked);
            Pager1.UserControlPreviousButtonClicked += new EventHandler(Pager1_UserControlPreviousButtonClicked);
}

  private void Pager1_UserControlNextButtonClicked(object sender, EventArgs e)
    {
    // write any code
    }


    private void Pager1_UserControlPreviousButtonClicked(object sender, EventArgs e)
    {
    // write any code
    }


No comments:

Post a Comment

What should you required to learn machine learning

  To learn machine learning, you will need to acquire a combination of technical skills and domain knowledge. Here are some of the things yo...