Tuesday 18 February 2014

Example for delegate in C# - here i will show how to call the child page button click on clicking the button which is inside user control of the parent page

In User Control lets name like horizantalmenu.ascx, i will define the event handler and i will use it in the particular button click event



 public event EventHandler ButtonClickDemo;   // define it globally

protected void Page_Load(object sender, EventArgs e)
 {
   
 }


protected void Button_Click(object sender, ImageClickEventArgs e)
    {
        ButtonClickDemo(sender, e);    // m using the event here
    }


--------------------------------------------------------------------------------------------------

In all the successive pages where you are calling  horizantalmenu.ascx in your page ,

trigger that event in the page load of your page

protected void Page_Load(object sender, EventArgs e)
    {
        HorizontalMenu.ButtonClickDemo += new EventHandler(GetMainQueryOnNotepad);
                                                                             // assigning with one function to call on button click
    }


 protected void GetMainQueryOnNotepad(object sender, EventArgs e)
    {
           /// you can do what ever you want to do in this function.
    }


No comments:

Post a Comment