ASP.NET Dynamic controls: Twice click problem
Sometimes, you need to click twice for the dynamic control to work.
Symptoms:
1. Your dynamic controls get loaded
2. You click on the button/other control
3. The page simply refreshes and no code is executed.
4. You try to debug the “onclick” method, but no break point is hit.
5. Next time when you hit the button, everything works properly.
Solution:
After creating the control, simply assign some id to it.
e.g.
myControl.id = “thisID”;
Somehow this is needed by the internal .NET code, so for the first time the click doesn’t work, but when you click next time, the id has already been generated, so the code works normally.

Thanks – I stumbled across many more complicated solutions that didn’t solve the problem for me. You helped me out a lot!
August 14th, 2008 at 1:57 AMOmg Thank you
November 18th, 2008 at 3:59 AM[...] ASP.NET Dynamic controls: Twice click problem [...]
April 16th, 2009 at 10:32 AM