Hi,
You seem to need to execute a common code for two ButtonClick events. I think the best way is to write the code to be executed in a separate method. Let's say the method be Common_Code(). Then do the following:
btnOk.Click += new EventHandler(btnOk_Click);
btnOk2.Click += new EventHandler(btnOk2_Click);
Then do this:
public void btnOk_Click(object sender, EventArgs e)
{
this.Common_Code();
}
public void btnOk2_Click(object sender, EventArgs e)
{
this.Common_Code();
}
While calling
Common_Code() method use appropriate parameters as you might be needing. The
this keyword helps you to point at the current object through which you are calling the method.
I think this will be better way to execute a common code.