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 () {

2
  • 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 2, 2016 at 1: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" - developer.mozilla.org/en-US/docs/Web/Security/…
    – Boris B.
    Mar 2, 2016 at 1:11

1 Answer 1

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");
1
  • Thank you Michael ... I found the answer on your link!
    – Veljko89
    Mar 2, 2016 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.