联合国predictable"发现用相同的ID'ctl35“多个控件&QUOT。当动态添加控件 [英] Unpredictable "Multiple controls with the same ID 'ctl35' were found." when dynamically adding controls

查看:189
本文介绍了联合国predictable"发现用相同的ID'ctl35“多个控件&QUOT。当动态添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,这个问题已经弹出了无数次,但没有一个职位,我可以找到已经能够帮助我解决这个问题。

I understand that this question has popped up countless times but none of the posts I can find have been able to help me with this issue.

每过一段时间,我收到了标题中的错误:被发现使用相同的IDctl35多个控件。 FindControl需要控件具有唯一的ID。这肯定不会发生所有的时间,它似乎只是刷新了几次会导致错误去了。

Every once in a while, I receive the error in the title: Multiple controls with the same ID 'ctl35' were found. FindControl requires that controls have unique IDs. This certainly does not happen all the time, and it seems that simply refreshing a few times will cause the error to go away.

我的页面基本上是有一个的UpdatePanel ,并在其中,用户是为了进入对应的命令,部分数据。由于可以有多个部分,还有就是创建一个新的面板按钮,创建输入字段,并将其添加到面板,然后将其添加到的UpdatePanel 。用户可以多次点击这个按钮来添加多个条目面板秒。为了做到这一点,我保持了列表<面板> 我添加了新的面板来每次用户需要一个新的条目字段。当页面收到回发(从Add按钮),然后我遍历列表并重新添加每个面板的UpdatePanel ,管理坚持现有条目面板。

My page essentially has an UpdatePanel and in it, the user is meant to enter data corresponding to parts of an order. Since there can be multiple parts, there is a button that creates a new Panel, creates input fields and adds it to the Panel, and then adds it to the UpdatePanel. A user can click this button multiple times to add multiple entry Panels. In order to accomplish this, I maintain a List<Panel> which I add the new Panel to every time the user wants a new entry field. When the page receives a postback (from the add button), I then iterate over the List and re-add each Panel to the UpdatePanel, which manages to persist the existing entry Panels.

由于这些字段是动态更新的,我就一定要设置字段,我会从那些将彼此独特的区分检索数据的ID。然而,如前所述,偶尔我也会要找到与ASP.NET自动生成的ID( ctl35 在这种情况下)的多个控件遇到的问题。在Chrome浏览器中呈现的HTML看一次我收到此错误,目前根本没有控制有 ctl35 作为其ID。此外,没有一个呈现的HTML甚至包含其ID结束该自动生成的ctlXX的任何元素。正因为如此,我能不明白的地方一个可能的命名冲突问题可以进来。这个错误不会发生的大部分时间,这也就是这里混乱的主要来源。

Since these fields are dynamically updated, I made sure to set the IDs of the fields that I'll be retrieving data from to those that will be unique and distinguishable from each other. However, as mentioned, I will occasionally run into issues about finding multiple controls with an ASP.NET auto-generated ID (ctl35 in this case). Looking at the rendered HTML in Chrome once I receive this error, there simply are no controls that have ctl35 as their ID. Furthermore, none of the rendered HTML even contains any elements whose IDs end in the auto-generated "ctlXX". Because of this, I can't understand where a possible named conflict issue can come in. The fact that this error doesn't occur most of the time also is a major source of confusion here.

什么这个问题可能是,或什么,我可能需要以解决此做任何想法?

Any ideas on what this issue may be, or what I might need to do in order to troubleshoot this?

推荐答案

请确保您要分配ID的所有动态创建的控件,而不仅仅是你需要从获取数据。我已经看到了使用上添加的控件默认的ID,当这种情况发生。

Make sure you are assigning ID's to all dynamically created controls, not just those you need to get data from. I've seen this happen when using default ID's on the added controls.

这篇关于联合国predictable&QUOT;发现用相同的ID'ctl35“多个控件&QUOT。当动态添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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