how can I clear the history of a textbox? I have set autocomplet=off and set AutoCompleteType to Disabled. The history / text appears when I double click the textbox in Chrome / Firefox, so when I click it the text will be inserted in the textbox. Is there a way to stop this behaviour via ASP.NET / HTML?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can turn off auto-fill for a particular TextBox by setting autocomplete attribute value to off as shown below:
<asp:TextBox Runat="server" ID="TextBox1" autocomplete="off"></asp:TextBox>
or
You Can just write a textbox properties in Page_Prerender event in my page(codebehind).
protected void Page_PreRender(Object sender, EventArgs e)
{
TextBox1.Attributes.Add(“autocomplete”, “off”)
}
It should fix it.
Method 2
You have to try on this line on your form
<form id="form2" runat="server" autocomplete="off">
Method 3
If it doesn’t work with autocomplete off, try to change the textbox/input name (not the Id) to a random value every time you load the page to the browser.
You can do it using javascript on window load as below:
window.onload = function () {
document.getElementById("yourTextboxId").name = "txt"+ Math.random();
}
Method 4
I would try something like this
<asp:TextBox ID="TextBox1" AutoCompleteType="Disabled" runat="server"></asp:TextBox>
And there is also a TextMode=”password” if its confidential stuf that also doesnt save autocomplete I think.
Method 5
strong textAfter testing autocomplete = “off” inside Input and form elements and get nothing Reading this Article guide me to a new reality about how browsers dealing with auto-completion, So I tested suggestions and it seems this one working: Setting autocomplete=”new-password” as advised:
If you are defining a user management page where a user can specify a
new password for another person, and therefore you want to prevent
auto filling of password fields, you can use
autocomplete=”new-password”; however, support for this value has not been implemented on Firefox.
Although I set non-password input elements to “new-value” and that is working too maybe for another suggestion in the article:
In some cases, the browser will continue suggesting autocompletion
values even if the autocomplete attribute is set to off. This
unexpected behavior can be quite puzzling for developers. The trick to
really enforcing non-autocompletion is to assign an invalid value to
the attribute, for example:autocomplete=”nope” Since this value is not a valid one for the
autocomplete attribute, the browser has no way to match it, and stops
trying to autocomplete the field.
Hope this help and useful for various scenarios.
Method 6
<%: Html.TextBoxFor(model => model.WEIGHT, new { autocomplete = "off" })%>
Method 7
As the other answerer said, disable AutoCompleteType property of the textbox.
Hide Copy Code
<asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
But this would not work in Mozilla Firefox. The best option would be to write a JavaScript onFocus of the text box to disable the autocomplete behaviour.
Hide Copy Code
Javascript:
Hide Copy Code
function disableautocompletion(id){
var passwordControl = document.getElementById(id);
passwordControl.setAttribute("autocomplete", "off");
}
Hope this helps!
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0