使用先前输入的值阻止文本框自动填充

Jos*_*ons 41 c# asp.net autofill

我有一个带有一些Textbox控件的asp页面.

默认情况下,浏览器会建议先前为每个框输入的值.

我想阻止某些文本框的行为.

有没有办法在所有主流浏览器中可靠地做到这一点?

我试过设定

AutoCompleteType="Disabled"
Run Code Online (Sandbox Code Playgroud)

但这似乎对Firefox没有影响.

这是我试图阻止的行为的图像.

在此输入图像描述

Pra*_*enu 67

对于Firefox

或者:

<asp:TextBox id="Textbox1" runat="server" autocomplete="off"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

或者从CodeBehind:

Textbox1.Attributes.Add("autocomplete", "off");
Run Code Online (Sandbox Code Playgroud)

  • asp标记似乎抛出一个警告说"此属性允许的值不包括'off'",但添加第二个代码块中显示的属性有效! (2认同)

Pan*_*kaj 11

自动填充需要从文本框中进行设置

<asp:TextBox ID="TextBox1" runat="server" autocomplete="off"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)


小智 8

这就是答案.

<asp:TextBox id="yourtextBoxname" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

AutoCompleteType = "已禁用"

如果您仍然在Firefox浏览器中获得预先填充的框,那么它的浏览器是错误的.你得走了

'选项' - >'安全'(标签) - >解开

'记住网站密码,然后单击"保存的密码"按钮删除浏览器保存的所有详细信息.

这应该可以解决问题

  • 你能解释一下为什么它能起作用所以他可以从中学习吗? (2认同)

Aru*_*tap 8

通过使 AutoCompleteType="Disabled",

    <asp:TextBox runat="server" ID="txt_userid" AutoCompleteType="Disabled"></asp:TextBox>  
Run Code Online (Sandbox Code Playgroud)

通过设置自动完成=“关闭”,

    <asp:TextBox runat="server" ID="txt_userid" autocomplete="off"></asp:TextBox>  
Run Code Online (Sandbox Code Playgroud)

通过设置表单自动完成=“关闭”,

    <form id="form1" runat="server" autocomplete="off">  
    //your content  
    </form>  
Run Code Online (Sandbox Code Playgroud)

通过使用 .cs 页面中的代码,

    protected void Page_Load(object sender, EventArgs e)   
    {  
        if (!Page.IsPostBack)  
        {  
            txt_userid.Attributes.Add("autocomplete", "off");  
        }  
    }  
Run Code Online (Sandbox Code Playgroud)

通过使用 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>  
Run Code Online (Sandbox Code Playgroud)

这是我的文本框,

    <asp:TextBox runat="server" ID="txt_userid" ></asp:TextBox>  
Run Code Online (Sandbox Code Playgroud)

通过在代码中设置文本框属性,

    protected void Page_Load(object sender, EventArgs e)   
    {  
        if (!Page.IsPostBack)  
        {  
            txt_userid.Attributes.Add("autocomplete", "off");  
        }  
    } 
Run Code Online (Sandbox Code Playgroud)

  • 设置 AutoCompleteType="Disabled" 在 SharePoint Web 部件中不起作用,它不会呈现任何内容。我不知道为什么。但设置 autocomplete="off" 确实有效。 (2认同)

5ee*_*ker 6

从CodeBehind尝试:

Textbox1.Attributes.Add("autocomplete", "off");
Run Code Online (Sandbox Code Playgroud)


Pra*_*abo 6

添加autocomplete="new-password"到密码字段就可以了。删除了 Chrome 中用户名和密码字段的自动填充。

<input type="password" name="whatever" autocomplete="new-password" />
Run Code Online (Sandbox Code Playgroud)