25 Jun

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.

3 Responses to “ASP.NET Dynamic controls: Twice click problem”

  1. 1
    Justin Says:

    Thanks – I stumbled across many more complicated solutions that didn’t solve the problem for me. You helped me out a lot!

  2. 2
    Jamsi Says:

    Omg Thank you :)

  3. 3
    ASP.NET Dynamic controls: Twice click problem « Jay’s Weblog: “Will code for future!” Says:

    [...] ASP.NET Dynamic controls: Twice click problem [...]

Leave a Reply