简体   繁体   English

清除 ASP.NET 中的文本框历史记录

[英]Clear textbox history in ASP.NET

how can I clear the history of a textbox?如何清除文本框的历史记录? I have set autocomplet=off and set AutoCompleteType to Disabled.我已设置 autocomplet=off 并将 AutoCompleteType 设置为 Disabled。 The history / text appears when I double click the textbox in Chrome / Firefox, so when I click it the text will be inserted in the textbox.当我在 Chrome/Firefox 中双击文本框时会出现历史记录/文本,因此当我单击它时,文本将插入文本框中。 Is there a way to stop this behaviour via ASP.NET / HTML?有没有办法通过 ASP.NET/HTML 阻止这种行为?

You can turn off auto-fill for a particular TextBox by setting autocomplete attribute value to off as shown below:您可以通过将 autocomplete 属性值设置为 off 来关闭特定文本框的自动填充,如下所示:

<asp:TextBox Runat="server" ID="TextBox1" autocomplete="off"></asp:TextBox> 

or

You Can just write a textbox properties in Page_Prerender event in my page(codebehind).您可以在我的页面(代码隐藏)中的 Page_Prerender 事件中编写一个文本框属性。

protected void Page_PreRender(Object sender, EventArgs e) { protected void Page_PreRender(Object sender, EventArgs e) {

 TextBox1.Attributes.Add(“autocomplete”, “off”)

} }

It should fix it.它应该修复它。

你必须在你的表格上尝试这一行

<form id="form2" runat="server" autocomplete="off">

If it doesn't work with autocomplete off, try to change the textbox/input name (not the Id) to a random value every time you load the page to the browser.如果关闭自动完成功能不起作用,请尝试在每次将页面加载到浏览器时change the textbox/input name (not the Id) to a random value

You can do it using javascript on window load as below:您可以在窗口加载时使用 javascript 来完成,如下所示:

window.onload = function () {
    document.getElementById("yourTextboxId").name = "txt"+ Math.random();
}

I would try something like this我会尝试这样的事情

<asp:TextBox ID="TextBox1" AutoCompleteType="Disabled" runat="server"></asp:TextBox>

And there is also a TextMode="password" if its confidential stuf that also doesnt save autocomplete I think.还有一个 TextMode="password" 如果它的机密内容也没有保存自动完成我认为。

strong text After testing autocomplete = "off" inside Input and form elements and get nothing Reading this Article guide me to a new reality about how browsers dealing with auto-completion, So I tested suggestions and it seems this one working: Setting autocomplete="new-password" as advised:强文本输入表单元素中测试autocomplete = "off"并且一无所获阅读这篇文章后,我对浏览器如何处理自动完成有了一个新的认识,所以我测试了建议,似乎这个建议有效:设置自动完成 =新密码”如建议:

If you are defining a user management page where a user can specify a new password for another person, and therefore you want to prevent auto filling of password fields, you can use autocomplete="new-password" ;如果你正在定义一个用户管理页面,用户可以在其中为另一个人指定一个新密码,因此你想防止自动填写密码字段,你可以使用autocomplete="new-password" however, support for this value has not been implemented on Firefox.但是,Firefox 尚未实现对这个值的支持。

Although I set non-password input elements to "new-value" and that is working too maybe for another suggestion in the article:尽管我将非密码输入元素设置为“新值”并且这也适用于文章中的另一个建议:

In some cases, the browser will continue suggesting autocompletion values even if the autocomplete attribute is set to off.在某些情况下,即使自动完成属性设置为关闭,浏览器也会继续建议自动完成值。 This unexpected behavior can be quite puzzling for developers.对于开发人员来说,这种意外行为可能令人费解。 The trick to really enforcing non-autocompletion is to assign an invalid value to the attribute, for example:真正强制执行非自动完成的技巧是为属性分配一个无效值,例如:

autocomplete="nope" Since this value is not a valid one for the autocomplete attribute, the browser has no way to match it, and stops trying to autocomplete the field. autocomplete="nope"由于此值对于 autocomplete 属性无效,因此浏览器无法匹配它,并停止尝试自动完成该字段。

Hope this help and useful for various scenarios.希望这对各种场景有所帮助和有用。

<%: Html.TextBoxFor(model => model.WEIGHT, new { autocomplete = "off" })%>

As the other answerer said, disable AutoCompleteType property of the textbox.正如另一个回答者所说,禁用文本框的 AutoCompleteType 属性。

Hide Copy Code隐藏复制代码

<asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled"></asp:TextBox>

But this would not work in Mozilla Firefox.但这在 Mozilla Firefox 中不起作用。 The best option would be to write a JavaScript onFocus of the text box to disable the autocomplete behaviour.最好的选择是编写一个 JavaScript onFocus 文本框来禁用自动完成行为。

Hide Copy Code隐藏复制代码

Javascript:
Hide   Copy Code
function disableautocompletion(id){ 
    var passwordControl = document.getElementById(id);
    passwordControl.setAttribute("autocomplete", "off");
}

Hope this helps!希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM