Объявите вашу функцию как событие:
protected void YourButtonClickEvent(object sender, EventArgs e)
{
// To hide your button
Button button = sender as Button;
button.visible = false;
// Your code
}
Объявите вашу кнопку и прикрепите к ней событие
Button button = new Button();
button.Click += new EventHandler(YourButtonClickEvent);