ASP.NET 4 Webforms clientid 后缀为“_0”
去年,我们将所有新功能转移到 ASP.NET MVC。
然而,我们仍然有大量遗留的 WebForms 页面,其中包含大量 JavaScript 代码,而且我们不会很快有机会升级它们。
最近,我们还迁移到了 ASP.NET 4,这似乎破坏了这些旧页面上的 JavaScript 代码负载。
之前的客户端 ID 是:
ctl001_masterControlName_panelControlName_controlWeWant
现在变成了:
ctl001_masterControlName_panelControlName_controlWeWant_0
_0
后缀从何而来? panelControlName
中只有一个 controlWeWant
,因此后缀没有添加任何值。
我知道硬编码的客户端 ID 对于 WebForms 来说是个坏主意;我们转向 ASP.NET MVC 的原因之一是 WebForms 生成的糟糕的 HTML。然而,对于这个遗留代码,我们坚持使用它,我宁愿不去改变它(直到有一天我们有一些空闲时间来正确地做它)。
为什么 ASP.NET 4 添加 _0
后缀?
我可以把它关掉吗?
还有其他方法可以避免吗?
Last year we moved all our new functionality to ASP.NET MVC.
However we still have a load of legacy WebForms pages with lots of JavaScript code, and we're not going to get the chance to upgrade them any time soon.
More recently we also moved to ASP.NET 4, and that seems to have broken a load of the JavaScript code on these legacy pages.
Where before the client id would be:
ctl001_masterControlName_panelControlName_controlWeWant
Now they have become:
ctl001_masterControlName_panelControlName_controlWeWant_0
Where does that _0
suffix come from? There's only one controlWeWant
in panelControlName
, so the suffix adds no value.
I know hardcoded client ids are a bad idea with WebForms; one of the reasons we moved to ASP.NET MVC was the awful HTML produced by WebForms. However for this legacy code we're stuck with it, and I'd rather not go changing it (until the day comes when we have some free time to do it properly).
Why is ASP.NET 4 adding the _0
suffix at all?
Can I turn it off?
Is there another way to avoid it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看ASP.NET 4.0 中的新增功能 - ClientID 生成更清晰的标记。它解释了 ASP.NET 4.0 中有关 id 生成的一些新功能。
Check out What is New in ASP.NET 4.0 - ClientID Generation for a Cleaner MarkUp. It explains some new functionality in ASP.NET 4.0 when it comes to id generation.