Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void Button1_Click(object sender, EventArgs e)
    {
        Button2_click()//Need to call Button2_click
    }


//===========================================================

Within Button1_click event I wish to call Button_2 click event.
Is it possible? if yes please provide the code..
Posted
Updated 13-Apr-11 19:12pm
v2

Instead of calling the event, why not create a method? Like this.

C#
protected void Button1_Click(object sender, EventArgs e)    
{        
     RunThis(); 
}

protected void Button2_Click(object sender, EventArgs e)
{
     RunThis();
}

public void RunThis()
{
    //put the content of Button2_Click event here.
}
 
Share this answer
 
Or you can do this.

C#
private void button1_Click(object sender, EventArgs e) {
    //option 1 of calling button2 click by simulating the click event
    button2.PerformClick();

    //option 2 of calling button2 click by calling the event itself
    button2_Click(sender, e);
}

private void button2_Click(object sender, EventArgs e) {
    MessageBox.Show("button2_Click");
}


Option 3 is to modify your code implementation just like what walterhevedeich suggested.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900