Several controls were found with the same identifier 'add0'. FindControl requires that controls have unique identifiers

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?

+4
source share
3 answers

A private static variable was used to store a dictionary of table names and cells so that table cells were not recreated during the page life cycle.

The key point is that it was marked as static - it had to be an instance variable, the end result was that when loading, when the queries started backing up, multi-proton queries shared this static dictionary.

exactly what happened, I’m not 100% sure, but at medium loads FindControl will find several controls with the same name, at very high loads it seems that one request will try to change the control (maybe add to it), in while it was in an invalid state from another request.

The end result β€” if you really don’t know what you are doing β€” prefer a variable like sto static static.

+2
source

How do you store information about the controls that need to be restored? If you use ViewState or ControlState, then I do not see how the load can affect things. The way any of the composite controls does something.

I will say that I saw your second error when using Infragistics UltraWebGrid and could never track it. From the call stack, it turned out that EnsureChildControls was called during the loading phase (or possibly LoadViewState).

+2
source

Everything you wrote seems correct and doable. This is most likely a problem with your control generation code. Perhaps if you publish some of them, we can better find a solution.

0
source

All Articles