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.
4 Answers
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"); });

- 4,209
- 1
- 22
- 25
-
Unfortunately, we are not using master pages, but a collection of aspx pages with a lot of embedded ascx controls. – Solid Performer Dec 23 '11 at 15:58
-
1@SolidPerformer: then place it on a user control that gets used everywhere. Pretty ASP.NET 1.x like but it worked back then. – Kris van der Mast Dec 23 '11 at 16:17
-
Master page... is that like a shared page in MVC? I have shared page that other pages inherit properties from. Should I just list that line in the shared page? – Kala J Nov 04 '13 at 17:02
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);
}
}

- 8,314
- 9
- 55
- 59
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.

- 12,696
- 2
- 31
- 47
-
Using autocomplete="off" on the form element works in Firefox 11. – Bryan Matthews Apr 24 '12 at 22:01
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.

- 21
- 2