Disable AutoComplete in Asp.NET

Most Browsers have a feature called AutoComplete which saves information that has previously been inputted like web addresses and form data. But sometimes, you may want to disable this feature for inputs like credit card information.

ASP.NET has the ability to override the user’s choice with the autocomplete attribute by setting it to off. This can be added to a form tag or any TextBox control and can be done using one of the following two properties:

  • AutoComplete=”Off”
  • AutoCompleteType=”Disabled”

View some examples after the break…

Below are some examples with AutoComplete=”Off”

  • <form Runat=”server” AutoComplete=”Off”></form>
  • <asp:TextBox ID=”txtCardNumber” runat=”server” AutoComplete=”Off” />
  • at runtime: txtCardNumber.Attributes.Add( “AutoComplete”, “Off” );

 You can find more info here or here

And next some examples with AutoCompleteType=”Disabled” 

  • <form Runat=”server” AutoCompleteType=”Disabled”></form>
  • <asp:TextBox ID=”txtCardNumber” runat=”server” AutoCompleteType=”Disabled”/>
  • at runtime: txtCardNumber.Attributes.Add( “AutoCompleteType”, “Disabled”);

Categories

5 Responses

  1. Please Explain the following code and how it is different than first piece of your code.

    And next some examples with AutoCompleteType=”Disabled”

    at runtime: txtCardNumber.Attributes.Add( “AutoCompleteType”, “Disabled”);

Leave a Reply

Your email address will not be published. Required fields are marked *