Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a button click event from another method

Tags:

c#

How can I call SubGraphButton_Click(object sender, RoutedEventArgs args) from another method?

private void SubGraphButton_Click(object sender, RoutedEventArgs args) { }  private void ChildNode_Click(object sender, RoutedEventArgs args) {    // call SubGraphButton-Click(). } 
like image 411
User1979 Avatar asked Jul 17 '12 08:07

User1979


People also ask

How do you call a method in Button click?

How can I call SubGraphButton_Click(object sender, RoutedEventArgs args) from another method? private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }

How do I call a Button click event from another class in C#?

A button click event is there to do what it says on the tin - handle the button click. The enclosed functionality is simply you saying "I'd like to do this when this happens". Extending this further you could make DoButtonStuff public and call it from elsewhere as you would with any other method.

How do I call a Button click event in another function in VB net?

PerformClick() works for any number of event handlers attached to Button2. Click (e.g. another form might have attached this event with AddHandler ), where as Button2_Click(sender, e) calls a specific handler.

How do you call a Button click event in code behind?

To simulate the button click in code, you simply call the event handler: Button1_Click(object sender, EventArgs e). protected void Page_Load(object sender, EventArgs e) { //This simulates the button click from within your code. Button1_Click(Button1, EventArgs.


2 Answers

You can easily do it by the following piece of code (assuming that name of your button is btnButton):

btnButton.PerformClick(); 
like image 77
Pedram Avatar answered Sep 21 '22 17:09

Pedram


You can call the button_click event by simply passing the arguments to it:

private void SubGraphButton_Click(object sender, RoutedEventArgs args) { }  private void ChildNode_Click(object sender, RoutedEventArgs args) {    SubGraphButton_Click(sender, args); } 
like image 27
patel.milanb Avatar answered Sep 20 '22 17:09

patel.milanb