ASP.NET 4 webforms clientid suffixed with `_0`
Last year w开发者_如何学Goe 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?
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.
精彩评论