将 asp.net 2.0 网站部署到 Framework 4.0 时 ClientID 发生变化
我有一个托管在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将来使用
<%=Control.ClientID%>
每次都会成功解析 - 无需更改代码。In the future use
<%=Control.ClientID%>
which will successfully resolve every time - without code changes.ASP.NET 4.0 中的控件具有
ClientIDMode
属性。如果您将其设置为AutoID
,ASP.NET 应该以与 ASP.NET 2.0 中相同的方式生成客户端 ID。这是一篇文章 解释了不同的客户端 id 模式。除了在控制级别设置 ClientIDMode 之外,您还可以在页面或应用程序级别设置它:
或
但我同意 leppie 的评论,即依赖生成的客户端 id 是危险的。
Controls in ASP.NET 4.0 have a
ClientIDMode
property. If you set this toAutoID
, 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:or
But I agree with leppie's comment that it is dangerous to rely on generated client ids.