I have a form with two buttons: btn_oldFile and btn_newFile. Both buttons, on click call the function btnOnClick:
btn_oldFile.Click += btnOnClick;
btn_newFile.Click += btnOnClick;
protected void OldFileBrowse_Click(object sender, EventArgs args)
{
//if btn_oldFile called
// print to tbx_OldFile
//else
//print to tbx_NewFile
}
For the most part, btnOnClick is to do the same thing no matter which button called itself, except for assigning a value to a variable. If btn_oldFile calls the method, I print some text to a textbox: tbx_OldFile, while if btn_newFile calls it, the text is printed to tbx_NewFile.
How can I ascertain which button was the one that called the method?
The object that raised the event is passed to the event handler as the sender parameter, so you can cast that to the correct type to access it.
Edit: You can then use a basic if statement to check which button it was.