3

I have a problem to simply clear TextBox text ... I am using asp.net and bit of JS for project.

But it seems Mozzila is to strong for my code and now it's bugging me.

Idea is simple ... user can log in, and as always mozzila ask "Save credentials" which is fine

enter image description here

But if user forget his password, select the link, I send him mail with URL, he comes back to new page which got text boxes

enter image description here

And for some reason Mozzila see my first TextBox as the one it "remembered the credentials"

enter image description here

So i tried next things

<script type="text/javascript">
    $(document).ready(function () {

        document.getElementById("MainContent_txtNewPass1").value = "";
        document.getElementById("MainContent_txtNewPass2").value = "";

    });

</script>

And

protected void Page_Load(object sender, EventArgs e)
{
    txtNewPass1.Attributes["AUTOCOMPLETE"] = "off";
    txtNewPass2.Attributes["AUTOCOMPLETE"] = "off";

    txtNewPass1.Text = "";
    txtNewPass2.Text = "";
}

Which didn't worked, as I wouldn't be asking this question ... IDs of those asp:TextBoxes are different, I don't understand why is this happening or how to stop it from happening?

EDIT

I am sure it's problem with Mozzila credential saving, as once I delete saved password, problem is gone. But at the end of a day, i just want to clear that TextBox.Text

SOLUTION

If anyone gets a same problem ... I solved it but using

window.onload = function () {
    document.getElementById("MainContent_txtNewPass1").value = "";
    document.getElementById("MainContent_txtNewPass2").value = "";
}

Instead $(document).ready(function () {

Veljko89
  • 1,813
  • 3
  • 28
  • 43
  • You won't believe it... The short is that you should include a third, visually hidden password field (`type='password' style='display: none' name='ignoreMe'`) before your actual password & confirm fields... – Boris B. Mar 02 '16 at 01:08
  • The reason is that browsers are being *too clever*, and are free to ignore `autocomplete` attribute for passwords, with the goal of having a "more secure web" - https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion – Boris B. Mar 02 '16 at 01:11

1 Answers1

2

Try this answer, the syntax is slightly different from what you have: https://stackoverflow.com/a/9686424/5013141

Instead of

txtNewPass1.Attributes["AUTOCOMPLETE"] = "off";

try this:

txtNewPass1.Attributes.Add("autocomplete", "off");
Community
  • 1
  • 1
Michael Fulton
  • 4,608
  • 3
  • 25
  • 41