gpt4 book ai didi

c# - .NET 4.5 中的 INamingContainer

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:01 24 4
gpt4 key购买 nike

我们最近从 .NET 3.5SP1 升级到了 .NET 4.5。我们发现使用 INamingContainer 接口(interface)的控件现在以不同方式呈现它们的 ClientID。

MS 文档说 INamingContainer 在控件的层次结构中创建了一个新的 ID 命名空间。

使用旧行为,我们的 ID 将如下所示:

<input id="MyContainer_txtName" />

但我们现在得到:

<input id="ctl00_ctl00_c_contentHolder_MyContainer_txtName" />

其中有 ct100 前缀和内容持有者控件名称。

使用它的示例类是:

public class MyTextBox : System.Web.UI.WebControls.TextBox, INamingContainer
{

}

为了向后兼容,我们设置了 ClientIDMode="AutoID"

我们可以像以前一样使用 ClientID="static" 手动为每个控件提供正确的 ID,但这对我们来说需要完成很多工作。

我想了解为什么 INamingContianer 没有像以前在旧版本的 .NET 中那样呈现。

提前致谢。

最佳答案

breaking change在 .NET4 中:

The ClientIDMode setting in ASP.NET 4 lets you specify how ASP.NET generates the id attribute for HTML elements. In previous versions of ASP.NET, the default behavior was equivalent to the AutoID setting of ClientIDMode. However, the default setting is now Predictable.

If you use Visual Studio 2010 to upgrade your application from ASP.NET 2.0 or ASP.NET 3.5, the tool automatically adds a setting to the Web.config file that preserves the behavior of earlier versions of the .NET Framework. However, if you upgrade an application by changing the application pool in IIS to target the .NET Framework 4, ASP.NET uses the new mode by default. To disable the new client ID mode, add the following setting in the Web.config file:

<pages ClientIDMode="AutoID" / >

关于c# - .NET 4.5 中的 INamingContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com