将 asp.net 2.0 网站部署到 Framework 4.0 时 ClientID 发生变化

发布于 2024-09-27 17:08:11 字数 229 浏览 0 评论 0原文

我有一个托管在 GoDaddy 上的网站,他们有 4.0 版运行时。 问题是服务器控件的客户端 ID 生成为“contentPlaceHolder1_drpBanks”,而之前(当网站位于其他服务器上时)生成为“ctl00_contentPlaceHolder1_drpBanks”。

我需要知道的是有一种方法可以解决这个问题,这样我就不必对代码进行任何更改。

就像 web.config 文件中的设置之类的。

I have a website which is hosted on GoDaddy they have version 4.0 runtime.
The issue is the client id of the server controls are generated as "contentPlaceHolder1_drpBanks" where it was earlier (when the website was on some other server) getting generated as "ctl00_contentPlaceHolder1_drpBanks".

What I need to know is there a way to resolve this so that I don't have to make any changes in the code.

Like a setting in web.config file or something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看轻我的陪伴 2024-10-04 17:08:11

将来使用 <%=Control.ClientID%> 每次都会成功解析 - 无需更改代码。

In the future use <%=Control.ClientID%> which will successfully resolve every time - without code changes.

北城挽邺 2024-10-04 17:08:11

ASP.NET 4.0 中的控件具有 ClientIDMode 属性。如果您将其设置为 AutoID ,ASP.NET 应该以与 ASP.NET 2.0 中相同的方式生成客户端 ID。这是一篇文章 解释了不同的客户端 id 模式。

除了在控制级别设置 ClientIDMode 之外,您还可以在页面或应用程序级别设置它:

<%@ Page Language="C#" ClientIDMode ="AutoID" ... %>

<system.web>
    <pages clientIDMode="AutoID" />
</system.web>

但我同意 leppie 的评论,即依赖生成的客户端 id 是危险的。

Controls in ASP.NET 4.0 have a ClientIDMode property. If you set this to AutoID, ASP.NET should generate client ids in the same way it did in ASP.NET 2.0. Here's an article that explains the different client id modes.

Besides setting ClientIDMode at the control level, you can also set it at the page or application level:

<%@ Page Language="C#" ClientIDMode ="AutoID" ... %>

or

<system.web>
    <pages clientIDMode="AutoID" />
</system.web>

But I agree with leppie's comment that it is dangerous to rely on generated client ids.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文