[c#] Prevent textbox autofill with previously entered values

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

This question is related to c# asp.net autofill

The answer is


Trying from the CodeBehind:

Textbox1.Attributes.Add("autocomplete", "off");

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


Autocomplete need to set off from textbox

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

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 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");  
        }  
    } 

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" />

This is the answer.

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

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


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to autofill

Disabling Chrome Autofill Detecting Browser Autofill Disable form autofill in Chrome without disabling autocomplete Prevent textbox autofill with previously entered values Google Chrome form autofill and its yellow background Override browser form-filling and input highlighting with HTML/CSS