ASP.Net的FindControl不工作 - 为什么? [英] ASP.Net FindControl is not working - How come?
问题描述
我已经使用的FindControl
在过去之前,.NET 2.0 / 3.0。这似乎是现在,由于某种原因,该ID是我的控制得到一个时髦的命名分配。例如,我分配一个ID为cbSelect一个复选框,但的FindControl没有找到它。当我看到它被分配在HTML ctl00_bodyPlaceHolder_ctl02_cbSelect
。
I have used FindControl
in the past, prior to .NET 2.0/3.0. It seems like now, for some reason, the ID's of my controls get a funky named assigned. For example I assigned an id "cbSelect" to a checkbox, but FindControl does not find it. When I view the HTML it was assigned ctl00_bodyPlaceHolder_ctl02_cbSelect
.
我还没有发现的FindControl的一个例子,提到。其实每个人似乎都只是用找到像正常对照组。
I have not found one example of FindControl that mentions that. In fact everyone seems to just use find control like normal.
所以,我做错了什么?没有净变化?任何人都可以摆脱一些轻到这对我来说,这是很无奈!
So, am I doing something wrong? Did .Net change? Can anyone shed some light onto this for me, it is really frustrating!
推荐答案
您可能正在使用一个母版或用户控件(ASCX),这是对客户端ID改变的原因。想象一下,你在用相同的ID为一体,在页面的母版页的控制。这会造成冲突。该ID的变化,确保所有客户端ID属性页上是唯一的。
You are probably using a MasterPage or user controls (ascx) and this is the reason the for client ids change. Imagine you have a control in the master page with the same id as one in the page. This would result in clashes. The id changes ensures all ClientID properties are unique on a page.
与MasterPages工作时的FindControl需要一些特别的注意。看一看 ASP.NET 2.0 MasterPages和的FindControl()。该工程的FindControl一个命名容器。该MastePage和页面是不同的命名容器。
FindControl needs some special attention when working with MasterPages. Have a look at ASP.NET 2.0 MasterPages and FindControl(). The FindControl works inside a naming container. The MastePage and the page are different naming containers.
这篇关于ASP.Net的FindControl不工作 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!