ASP .NET Dynamically adding EventHandlers to button on Page_Load. EventHandler's do not fire the fir
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-04T13:46:29Z
Indexed on
2010/05/04
13:48 UTC
Read the original article
Hit count: 178
Background: I am customizing an existing ASP .NET / C# application. It has it's own little "framework" and conventions for developers to follow when extending/customizing its functionality. I am currently extending some of it's administrative functionality, to which the framework provides a contract to enforce implementation of the GetAdministrationInterface()
method, which returns System.Web.UI.Control
. This method is called during the Page_Load()
method of the page hosting the GUI interface.
Problem: I have three buttons in my GUI, each of which have been assigned an Event Handler. My administration GUI loads up perfectly fine, but clicking any of the buttons doesn't do what I expect them to do. However, when I click them a second time, the buttons work.
I placed breakpoints at the the beginning of each event handler method and stepped through my code. On the first click, none of the event handlers are triggered. On the second click, they are triggered.
Any ideas?
Example of Button Definition
Button btn = new Button();
btn.Text = "Click Me Locked Screen";
bth.Click += new EventHandler(Btn_Click);
Example of Event Handler Method Definition
void Btn_Click(object sender, EventArgs e)
{
// Do Something
}
© Stack Overflow or respective owner