ASP.NET 2.5前缀为ctl00,ASP.NET 4不为ctl00加前缀

Ste*_*ven 15 asp.net

有谁知道为什么ASP.NET 4 ctl00在ASP控件上删除了前缀?

我错过了一个场景吗?

Mat*_*ott 30

在ASP.NET 4.0中,他们引入了对更清晰的HTML语法的支持.你可以在Scott Gu的博客上看到它.如果您想要客户端ID的经典模型,可以调整web.config:

<configuration>
    <system.web>
        <pages controlRenderingCompatibilityVersion="3.5" />
Run Code Online (Sandbox Code Playgroud)

这将使您的应用程序升级更容易.您可以使用Control.ClientIDMode属性更改每个控件(和每页),也可以在Web配置中设置:

<configuration>
    <system.web>
        <pages clientIDMode="AutoID|Predictable|Static|Inherit" />
Run Code Online (Sandbox Code Playgroud)

AutoID 使用经典的ASP.NET 2.0模型呈现控件.