I am programatically calling the following code after a different button click:
Button b = new Button();
b.Click += new EventHandler(b_Click);
b.Text = "click me";
The button is created and appears fine and the following code is also in the .cs file:
public void b_Click(Object sender, System.EventArgs e)
{
txtlabel.Text = "ABC";
}
When i click the button i created programatically, it goes back as if i had loaded the page the first time. Adding a breakpoint in the b_click function does not pause telling me for some reason it is not running the event handler.
I figured it out, the problem was that i was not re-creating all the buttons at the beginning of each page load so when the page loaded after clicking the button, the button did not exists so the click handler was not referencing anything.