Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear TextBox.Text C#/JS

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

like image 264
Veljko89 Avatar asked Jun 03 '26 10:06

Veljko89


1 Answers

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");
like image 164
Michael Fulton Avatar answered Jun 05 '26 00:06

Michael Fulton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!