karlhsc
asked on
OnClick Variables
Hello, I am using C# to create an ASP.NET website. Here's my issue:
I have a standard button on one page. This button has an onclick setup to fire a method. I have a second button on this page. When the user clicks on this button, its onclick setup fires another method which does some stuff, BUT at the end of this method, I would like it to fire the first button's onclick method.
Currently when I add the name of the first button's onclick method ( button1_Click() ) to the end of the second button's onclick method, this error is displayed: "No overload method for..takes 0 arguments".
I know what this error means: the system wants me to include two variables when calling button1_click, which are the default: object sender, EventArgs e
What are object sender, EventArgs e and how do I include them in my call to button1_Click from the button2_click method?
Thank you in advance.
I have a standard button on one page. This button has an onclick setup to fire a method. I have a second button on this page. When the user clicks on this button, its onclick setup fires another method which does some stuff, BUT at the end of this method, I would like it to fire the first button's onclick method.
Currently when I add the name of the first button's onclick method ( button1_Click() ) to the end of the second button's onclick method, this error is displayed: "No overload method for..takes 0 arguments".
I know what this error means: the system wants me to include two variables when calling button1_click, which are the default: object sender, EventArgs e
What are object sender, EventArgs e and how do I include them in my call to button1_Click from the button2_click method?
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@tgerbert - You are of course correct - just figured it wasn't likely to be an issue in this scenario so skimmed over it :)
Just to expand a little. It is possible to use a single event handler as the target for an event on multiple controls. In a scenario like that you may want to cast "sender" in order to find out which control raised the event and act accordingly.
Just to expand a little. It is possible to use a single event handler as the target for an event on multiple controls. In a scenario like that you may want to cast "sender" in order to find out which control raised the event and act accordingly.
ASKER
tgerbert: thank you for the additional information. I see the merit in the architecture you provided.
Also, I would suggest moving the code that actually does "stuff" into it's own method(s), and then calling those methods from the button event handlers:
Open in new window