Prevent textbox autofill with previously entered values
Asked Answered
E

8

50

I have an asp page with some Textbox controls on it.

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.

Here is an image of the behavior I'm trying to prevent.

enter image description here

Elledge answered 13/3, 2012 at 14:38 Comment(1)
Note it doesn't seem to be possible to turn autocomplete off in IE #22329108Release
J
82

For firefox

Either:

<asp:TextBox id="Textbox1" runat="server" autocomplete="off"></asp:TextBox>

Or from the CodeBehind:

Textbox1.Attributes.Add("autocomplete", "off");
Joses answered 13/3, 2012 at 14:50 Comment(3)
the asp markup seems to throw a warning saying "The values permitted for this attribute do not include 'off'" but adding the attribute as it shows in the second code blocks works!Sky
The first line works for me, just ignore the warning :PTaker
This got me where I needed to go. For a Telerik RadTextBox it's <telerik:RadTextBox ... AutoCompleteType="Disabled" />.Classis
B
12

By making 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,

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

By Using 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");  
        }  
    } 
Baugher answered 1/6, 2018 at 8:45 Comment(1)
Setting AutoCompleteType="Disabled" didn't work in SharePoint web part, it didn't render anything. I don't know why. But setting autocomplete="off" did work.Sacrilegious
H
11

Autocomplete need to set off from textbox

<asp:TextBox ID="TextBox1" runat="server" autocomplete="off"></asp:TextBox>
Hal answered 13/3, 2012 at 14:54 Comment(1)
as my comments above state, this no longer seems to work. need to do it via code using the Attributes.Add as shown aboveSky
T
7

This is the answer.

<asp:TextBox id="yourtextBoxname" runat="server" AutoCompleteType="Disabled"></asp:TextBox>

AutoCompleteType="Disabled"

If you still get the pre-filled boxes for example in the Firefox browser then its the browser's fault. You have to go

'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

Timmons answered 23/9, 2015 at 13:7 Comment(1)
Can you explain him why does it work so he can learn from it?Chitarrone
H
6

Trying from the CodeBehind:

Textbox1.Attributes.Add("autocomplete", "off");
Hedberg answered 16/11, 2013 at 8:44 Comment(0)
I
6

Adding autocomplete="new-password" to the password field did the trick. Removed auto filling of both user name and password fields in Chrome.

<input type="password" name="whatever" autocomplete="new-password" />
Iasis answered 14/3, 2019 at 14:20 Comment(1)
This was the only solution that did worked for me. Thank you so much.Headstream
B
1

Please note that for Chrome to work properly it needs to be autocomplete="false"

Bilk answered 15/9, 2015 at 15:3 Comment(0)
A
0

This works for me

   <script type="text/javascript">
        var c = document.getElementById("<%=TextBox1.ClientID %>");
        c.select =
        function (event, ui) 
        { this.value = ""; return false; }
    </script>
Amoebic answered 19/12, 2013 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.