We have a mature application which handles sensitive data and has grown to several hundred pages and controls. It is now a requirement to set autocomplete=off for all the forms and textboxes in the entire application. I don’t believe there is a global web.config setting that would do this, so what would be the best way? My initial thought was to use a PageBase class (which all pages inherit from) to dynamically find all Form and TextBox controls and dynamically add the attribute autocomplete=”off”. Does this seem reasonable or is there a better way? Thanks for any recommendations.
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
If all your pages have master page then try to disable autocomplete for input controls using Jquery in the master page.
You can place the below code in the master page
$(document).ready(function () { $("input").attr("autocomplete", "off"); });
Method 2
Always try to use a BasePage and inherits all pages from it, it’s a good practice and it help later a lot when the project gradually become a monster ….. and in this scenario if you already did it then .. it’s one line code …
public abstract class BasePage : Page
{
protected override void OnLoad(EventArgs e)
{
//Handling autocomplete issue generically
if (this.Form != null)
{
this.Form.Attributes.Add("autocomplete", "off");
}
base.OnLoad(e);
}
}
Method 3
Try adding autocomplete=”off” to just your form element rather than every single control. At least in IE this should turn it off for all the controls within the form.
Yes, if you lack the ability to use a master page for some reason, inheritance is a reasonable way to accomplish what you want.
Method 4
If you are using MVC, then under Views/Shared, add it to your _Layout.csstml
As Pavan said:
$(document).ready(function ()
{
$("input").attr("autocomplete", "off");
});
If you want some controls to work, and some not then use:
$("#myInputboxName").attr("autocomplete", "off");
myInputboxName is the name you called the control’s id.
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