Reputation: 624
This is the example:
https://drive.google.com/file/d/0B4CwNQ_rOoDVUVZSY3h0QXVBaG8/view
<asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password" autocomplete="off"></asp:TextBox>
I want to prevent the password autocomplete in my system. It seems it is not working with autocomplete="off"
. I could prevent it using $('#<%= TextBoxPassword.ClientID %>').val("");
when the window is loading, but in Chrome there is a another option call Use password for:
and someone can get the password by using that. So how do I prevent it?
I don't mean the "yellow background" thing that belongs to chrome.
Upvotes: 15
Views: 10416
Reputation: 149
For me, none of those solved the issue. I found two workaround which solves it.
First, Chrome / FF / IE omits set autocomplete info to fields set to readonly, Second, also omits when the field(s) have init value != empty.
So, you need to setting the form fields to read only and then removing the attribute once the user focus them (can be done with Javascript, or programatically in code behind).
For example, in simple html:
<input readonly="readonly" onfocus="this.removeAttribute('readonly');" type="text" value="[email protected]">
In html-aspx:
<asp:TextBox runat="server" ID="TxtEmployeId" ReadOnly="true" MaxLength="100"/>
Alternatively / additionally, you can set a fixed value for the field (in the numeric field case, you can set to 0).
if (!Page.IsPostBack)
{
TxtEmployeId.Text = "@";
}
I know this solution is not confortable at all, for each field / page you have with the problem you need to apply this. But it works :)
Upvotes: 0
Reputation: 156
In IE you need to do like this:
<asp:TextBox ID="TextBoxPassword" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
In all other browsers, this:
<asp:TextBox ID="TextBoxPassword" runat="server" autocomplete="Off"></asp:TextBox>
Im pretty sure you need the 'off' to be: 'Off'
In HTML, as you mention you can use the;
<form action="demo_form.asp" autocomplete="on">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
E-mail: <input type="email" name="email" autocomplete="off"><br>
<input type="submit">
</form
Either on the form or the input itself.
Maybe something else in your code is enabling it again?
Hope this works. Just tested and had no problem. Both IE and Chrome.
Upvotes: 3