Friday, July 3, 2009

Disabling AutoComplete Feature

In Web forms, when we start type in the text box, we will get the values we have typed in that field before. This is known as Auto Complete Feature. This feature is helpful in entering redundant values.

Sometimes we may want to turn off the feature as we should not reveal secret information such as social security number or credit card number.


How to turn off the auto complete feature.


To turn off auto complete for the entire form, all we need to do is add an attribute to our form tag, like this:



< form id="Form1" method="post" runat="server" autocomplete="off" >

.....

< /form >




How to turn off auto-complete feature in Control

We can do it at design time or at run time.

At design time:

Drag the asp text box control and place on the form and include the following



< asp:TextBox Runat="server" ID="Textbox1" autocomplete="off" >< /asp:TextBox >




But note that VS.NET will underline it with a squiggly saying that textbox does not have an attribute for autocomplete - but it will still work

At runtime:



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

No comments:

Post a Comment