C# 防止文本框自动填充以前输入的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9686224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prevent textbox autofill with previously entered values
提问by JosephStyons
I have an asp page with some Textbox controls on it.
我有一个带有一些文本框控件的 asp 页面。
By default, the browser will suggest previously entered values for each box.
默认情况下,浏览器将为每个框建议先前输入的值。
I'd like to prevent that behavior for some of the textboxes.
我想防止某些文本框出现这种行为。
Is there a way to reliably do that across all major browsers?
有没有办法在所有主要浏览器中可靠地做到这一点?
I've tried setting
我试过设置
AutoCompleteType="Disabled"
But that seems to have no effect in Firefox.
但这在 Firefox 中似乎没有效果。
Here is an image of the behavior I'm trying to prevent.
这是我试图阻止的行为的图像。


采纳答案by PraveenVenu
For firefox
对于火狐
Either:
任何一个:
<asp:TextBox id="Textbox1" runat="server" autocomplete="off"></asp:TextBox>
Or from the CodeBehind:
或者从代码隐藏:
Textbox1.Attributes.Add("autocomplete", "off");
回答by Pankaj
Autocomplete need to set off from textbox
自动完成需要从文本框出发
<asp:TextBox ID="TextBox1" runat="server" autocomplete="off"></asp:TextBox>
回答by 5eeker
Trying from the CodeBehind:
从 CodeBehind 尝试:
Textbox1.Attributes.Add("autocomplete", "off");
回答by George Dgebuadze
This works for me
这对我有用
<script type="text/javascript">
var c = document.getElementById("<%=TextBox1.ClientID %>");
c.select =
function (event, ui)
{ this.value = ""; return false; }
</script>
回答by Mike
Please note that for Chrome to work properly it needs to be autocomplete="false"
请注意,要使 Chrome 正常工作,它需要 autocomplete="false"
回答by sebastian
This is the answer.
这就是答案。
<asp:TextBox id="yourtextBoxname" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
AutoCompleteType="Disabled"
AutoCompleteType="禁用"
If you still get the pre-filled boxes for example in the Firefox browser then its the browser's fault. You have to go
如果您仍然在 Firefox 浏览器中看到预填充的框,那么这是浏览器的问题。你得走了
'Options' --> 'Security'(tab) --> Untick
“选项”-->“安全”(选项卡)--> 取消勾选
'Remember password for sites and click on Saved Passwords button to delete any details that the browser has saved.
'记住网站的密码,然后单击“已保存的密码”按钮以删除浏览器已保存的任何详细信息。
This should solve the problem
这应该可以解决问题
回答by ArunPratap
By making AutoCompleteType="Disabled",
通过使 AutoCompleteType="Disabled",
<asp:TextBox runat="server" ID="txt_userid" AutoCompleteType="Disabled"></asp:TextBox>
By setting autocomplete="off",
通过设置自动完成=“关闭”,
<asp:TextBox runat="server" ID="txt_userid" autocomplete="off"></asp:TextBox>
By Setting Form autocomplete="off",
通过设置表单自动完成=“关闭”,
<form id="form1" runat="server" autocomplete="off">
//your content
</form>
By using code in .cs page,
通过使用 .cs 页面中的代码,
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txt_userid.Attributes.Add("autocomplete", "off");
}
}
By Using Jquery
通过使用 Jquery
<head runat = "server" >
< title > < /title> < script src = "Scripts/jquery-1.6.4.min.js" > < /script> < script type = "text/javascript" >
$(document).ready(function()
{
$('#txt_userid').attr('autocomplete', 'off');
});
//document.getElementById("txt_userid").autocomplete = "off"
< /script>
and here is my textbox in ,
这是我的文本框,
<asp:TextBox runat="server" ID="txt_userid" ></asp:TextBox>
By Setting textbox attribute in code,
通过在代码中设置文本框属性,
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txt_userid.Attributes.Add("autocomplete", "off");
}
}
回答by Prabo
Adding autocomplete="new-password"to the password field did the trick. Removed auto filling of both user name and password fields in Chrome.
添加autocomplete="new-password"到密码字段可以解决问题。删除了 Chrome 中用户名和密码字段的自动填充。
<input type="password" name="whatever" autocomplete="new-password" />

