ASP.net 覆盖表单元素的客户端 ID

发布于 2024-09-29 12:11:08 字数 339 浏览 1 评论 0原文

给定一个文本框:

<asp:Textbox runat="server" id="txtAddress1" />

这呈现为类似于:

<input name="ctl00$mainContent$txtAddress1" type="text" id="ctl00_mainContent_txtAddress1" />

我不认为浏览器自动完成功能会将此名称/ID 识别为可以自动填充的字段,它们不是标准识别名称。

有没有什么方法可以覆盖客户端 ID,以便自动完成功能有更好的机会识别它们?

Given a textbox:

<asp:Textbox runat="server" id="txtAddress1" />

This renders as something similar to:

<input name="ctl00$mainContent$txtAddress1" type="text" id="ctl00_mainContent_txtAddress1" />

I don't think browsers autocomplete features recognise this name/ID as a field they can autofill, they are not standard recognised names.

Is there any way to overide the client ID's so that autocomplete has a better chance of recognising them?

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

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

发布评论

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

评论(2

喜爱皱眉﹌ 2024-10-06 12:11:08

2分这个。

1) ASP.Net 4.0 中引入了“覆盖名称”功能,对于任何属性,您都可以选择硬编码名称而不是动态名称。您需要小心这一点,因为您不希望两个对象共享一个名称。

2) ASP.Net 2.0 及更高版本(可能在 v1.0 中)在控件上有一个名为“AutoCompleteType”的属性,该属性向浏览器提示框中需要哪种类型的信息。

2 Points with this.

1) The "Override the Name" feature was introduced in ASP.Net 4.0, where for any property you can choose a hardcoded name instead of the dynamic name. You need to be careful on this as you don't want 2 objects sharing a name.

2) ASP.Net 2.0 and above (may have been in v1.0) has a property on the control called "AutoCompleteType" which provides a hint to the browser on what sort of information is required in the box.

椒妓 2024-10-06 12:11:08

假设您使用的是 Asp.net 4.0,并且您了解 DJIDave 提到的要点,您可以在控件上使用 ClientIDMode 属性,并将其设置为“静态”。然后,您在 Asp.Net 的 Id 字段中指定的内容都将被带入您的最终标记,并且不会被 Asp.Net 'mangled'(因为需要更好的词)。

Assuming you're using Asp.net 4.0, and you're aware of the points mentioned by DJIDave, you can use the ClientIDMode property on a control, and set it to 'Static'. Then, what ever you specify in the Id field in Asp.Net will be brought through to your final markup, and will not be 'mangled' (for want of a better word) by Asp.Net.

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