Sunday, September 20, 2015 Different ways to disable auto-fill in browser for a textbox

In this article I am going to explain different ways to disable auto-fill for a textbox in


All major browsers (Google chrome, Mozilla firefox, Safari and Internet explorer) has default functionality of auto complete the textboxes values means when user start to type value in textbox gets a dropdown like prefilled values in that particular textbox . We can disable the auto fill settings of browsers by uncheck the enable autofill option in browsers settings. Different ways to disable auto-fill in browser for a textbox

This is manual option that will be performed by the each user on their browsers. But has option if we implement that, no need to make changes in browsers settings.


We have three ways to disable the autofill.
Method 1:
We can disable it by set autocomplete="off" the in the form tag. It will disable it for entire form.
<form autocomplete="off" id="form1" runat="server">

Method 2:
To disable autofill for a particular textbox set autocomplete="off"
<asp:TextBox ID="txtname" runat="server" autocomplete="off"></asp:TextBox>

Method 3:
We can also disable the autofill from code behind.
txtaddress.Attributes.Add("autocomplete", "off");

HTML Markup:
<form autocomplete="off" id="form1" runat="server">
            <tr><td>Name :</td><td><asp:TextBox ID="txtname" runat="server" autocomplete="off"></asp:TextBox></td></tr>
            <tr><td>Address :</td><td><asp:TextBox ID="txtaddress" runat="server" autocomplete="off"></asp:TextBox></td></tr>
            <tr><td>Salary :</td><td><asp:TextBox ID="txtsalary" runat="server" autocomplete="off"></asp:TextBox></td></tr>
            <tr><td></td><td><asp:Button ID="btnsave" runat="server" Text="Save" /></td></tr>

Write the below given code on page load event.
protected void Page_Load(object sender, EventArgs e)
        txtaddress.Attributes.Add("autocomplete", "off");
        txtsalary.Attributes.Add("autocomplete", "off");

Protected Sub Page_Load(sender As Object, e As EventArgs)
        txtaddress.Attributes.Add("autocomplete", "off")
        txtsalary.Attributes.Add("autocomplete", "off")
    End Sub

Build and run the project. To test it insert the record via click on submit button. After that again type the same value as you enter earlier.

   In this article we have learn to how we can disable the auto-fill in browser for a textbox using C# and VB.netI hope you enjoyed this article. 

1 comment:

  1. Good Article but This does not work for chrome. (version 47)