Previously called: how to work with dynamically created controls under loading in aspx
in response to the question below: information needed to determine which recovery controls are contained in the selected viewstate.
I dynamically create controls on the codebehind page - these controls are connected to click handlers, so when the postback occurs, I have to re-create the previous set of controls, then clear the controls and generate a new set of controls based on the previous click.
This is encoded and works correctly under normal circumstances:
in Page_Load if not postback generate default buttons else if postback re-generate buttons that were shown on last page in click_handler Clear the dynamically generated buttons created in the Page_Load generate new buttons based on the specific click being handled
however, when the server is under load, we begin to get problems:
With 5 users per second, we start to get an exception: Several controls were found with the same identifier 'add0'. FindControl requires that controls have unique identifiers.
With 100 users per second, we begin to get an exception: The control collection cannot be changed during the phases DataBind, Init, Load, PreRender or Unload.
After that, all subsequent requests receive the same error, and IIS needs to be restarted.
What could be the reason for this and how can I avoid it? Is it possible to rewrite html requests and interfere with each other at boot time? do objects somehow by hand after page unloading in such a way as to allow the next page load to go through them?