被发现使用相同的ID“ADD0”多重控制。 FindControl需要控件具有唯一的ID [英] Multiple controls with the same ID 'add0' were found. FindControl requires that controls have unique IDs

查看:469
本文介绍了被发现使用相同的ID“ADD0”多重控制。 FindControl需要控件具有唯一的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously叫:如何处理动态创建的控件负荷下的aspx

Previously Called: How to deal with dynamically created controls under load in aspx

响应于以下一个问题:要确定其控制以恢复包含在专用视图状态对象所需的信息

in response to a question below: the information required to determine which controls to restore is contained in a dedicated viewstate object.

我动态在codebehind页面创建控件 - 这些控件都迷上了当回发时,我必须重新创建previous组控件,然后清除控制下单击处理函数,以便与生成基础上,previous单击新的控件集。

I am dynamically creating controls in the codebehind page - these controls are all hooked up to click handlers so when a postback occurs I must re-create the previous set of controls, then clear the controls down and generate the new set of controls based on the previous click.

这是codeD和esentially一般情况下正常工作如下:

This is coded and working correctly under normal circumstances esentially as follows:

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 comes under load we start getting problems:

通过每秒,我们开始变得异常5的用户:
被发现使用相同的IDADD0'的多个控件。 FindControl需要控件具有唯一的ID。

With 5 users per second we start getting the exception: Multiple controls with the same ID 'add0' were found. FindControl requires that controls have unique IDs.

通过每秒,我们开始变得异常100个用户:
控件集合不能的DataBind,初始化,加载,preRender期间修改或卸载阶段。

With 100 users per second we start getting the exception: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.

一旦发生这种情况的所有后续请求得到相同的错误和IIS已重新启动。

Once this occurs all subsequent requests get the same error and IIS has to be re-started.

什么可以causeing这一点,我怎么能避免呢?不要HTML请求可能会覆盖并互相干扰下的负载是什么时候?就莫名其妙的物体在手的方式在页面卸载,将允许下一个页面加载到被绊倒后,身边?

What could be causeing this and how can I avoid it? Do html requests possibly overwrite and interfere with each other when under load? do objects somehow hand around after a page unload in a manner that would allow the next page load to trip over them?

推荐答案

一个私有静态变量是用来储存姓名和表单元格的字典,这样的表格单元格不会得到页面生命周期中重新创建。

A private static variable was being used to store a dictionary of names and table cells so that table cells would not get re-created during the page lifecycle.

关键的一点是,它的特点是静态的 - 它应该是一个实例变量 - 最终的结果是在负载下时请求启动备份然后multpile请求都共享此静态字典

The key point is that it was marked static - it should have been an instance variable - the end result being that under load when requests started backing up then multpile requests were sharing this static dictionary.

到底发生了什么我不是100%肯定 - 但中等负荷下的FindControl会发现同名的多个控件,非常高负载下,似乎一个请求会尝试修改控件(可能添加到它),而它在从其他请求无效状态。

exactly what happened i'm not 100% sure - but under medium loads FindControl would find multiple controls of the same name, under very high loads it seems one request would try to modify a control (probably add to it) while it was in an invalid state from the other request.

最终的结果 - 如果你真的不知道你做什么 - preFER实例变量STO静态变量

End result - if you dont really know what your doing - prefer instance variable sto static variables.

这篇关于被发现使用相同的ID“ADD0”多重控制。 FindControl需要控件具有唯一的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆