1

I have 2 simple controls. When my page loads, it automatic fills up.

enter image description here

I got following reference which suggests to set Autocomplete = Off

Stop browser from filling textboxes with details

https://forums.asp.net/t/1107643.aspx?How+do+you+disable+history+info+on+a+textbox+

But it doesn't work. You can see above screenshot. It is email field which automatically filled by reference of cache when page loaded. It is going to be headache.

Can anybody please suggest me how to prevent this?

Please note, I don't want to clear history. I just want that this should not be filled up when my page loads.

Community
  • 1
  • 1
Nanji Mange
  • 2,155
  • 4
  • 29
  • 63

3 Answers3

2

You cannot disable the autofill programatically. It is browser behaviour, and it differs per browser. You can disable it per browser, but that is up to the client.

According to this answer, you can add hidden dummy textboxes before the actual ones to throw off the autocomplete.

<input style="display:none" type="text" name="fakeusername"/>
<input style="display:none" type="password" name="fakepassword"/>
Community
  • 1
  • 1
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • Thanks. In my case, fields are not predecided. It's upto user. User is free to set fields on the Form from the given list of fields. And I can add fake field dynamically just before such fields. But the point is how can I identify that this field will be autofilled. i.e field name can be `email or username or email1`. Please guide me. – Nanji Mange Jan 17 '17 at 13:21
  • That's the whole problem, you can't identify them. – VDWWD Jan 17 '17 at 13:22
  • :( I am damn stuck for this. – Nanji Mange Jan 17 '17 at 13:45
  • But the above trick can still work I think. For every password field the user adds you can also add dummies. – VDWWD Jan 17 '17 at 13:54
  • Yes, I am implementing it. And trying to identify as much as possible cases. Let see how many it can cover. Thanks for all your efforts :) – Nanji Mange Jan 17 '17 at 14:45
  • 1
    Hi, I got the solution by this. If password field is in already in design, then set like this `` – Nanji Mange Jan 18 '17 at 04:27
  • 1
    If it's dynamic, `TextBox textControl = new TextBox(); textControl.Attributes.Add("autocomplete", "new-password"); textControl.Attributes.Add("placeholder", "* * * * * *");` – Nanji Mange Jan 18 '17 at 04:29
2

Adding autocomplete="new-password" will solve your problem. I have tried autocomplete="off" and autocomplete="false" both did not work for me. This works perfectly autocomplete="new-password"

Afnan Ahmad
  • 2,492
  • 4
  • 24
  • 44
  • Yeah but this case still creates problem. I don't know if it's because of "new-password" or something else. When I edit the record, it get value of password from DB and set like `txt_password.Text = value`. At this time, it keeps Password blank and shows placeholder. Can you please check it? – Nanji Mange Jan 18 '17 at 06:38
  • what is the markup for your placeholder ? Can you show that @NanjiMange – Afnan Ahmad Jan 18 '17 at 06:47
  • This is not because of this `"new-password"` its because of your placeholder markup. You need some thing like this if you are using jQuery then `$('#password').keypress(function(){ $('#placeholder').html(""); });` @NanjiMange – Afnan Ahmad Jan 18 '17 at 06:48
  • 1
    This does not work with FireFox unfortunately. Only for Chrome. – VDWWD Jan 18 '17 at 07:37
  • @VDWWD & Afnan Ahmad, it's done. I set this `txt_password.Attributes["type"] = "password";` rather than `txt_password.TextMode=TextBoxMode.Password` and things get working. Plz suggest your thought if this way is not appropriate. – Nanji Mange Jan 19 '17 at 03:37
1

I am not sure, but this could be done by the browser. In IE11, there is this setting:

Autocomplete Settings in IE11

Maybe it helps to delete the AutoComplete history and disable AutoComplete.

Happy DNNing! Michael

Michael Tobisch
  • 1,034
  • 6
  • 15
  • Thanks but I don't want user set manually for each browser. I want to set programmatically. – Nanji Mange Jan 17 '17 at 05:39
  • OK, I understand. Theoretically, this attribute (autocomplete="off") should do it, but oviously you're not lucky with it. Have you tried to turn off the feature for the whole form, like:
    – Michael Tobisch Jan 18 '17 at 09:06
  • Another thing seems to be that some browsers don't care about this setting. I found this thread: http://stackoverflow.com/questions/25228951/autocomplete-off-not-working-for-google-chrome that also provides a fix. – Michael Tobisch Jan 18 '17 at 09:10
  • Regarding my first comment here: when you are on DNN you have to inject the attribute in code behind. – Michael Tobisch Jan 18 '17 at 09:14