Question

I want to prevent saving of username and password on login. I have used autocomplete="off" in the past but with Explorer 11 this doesn't work. According to answers given here I put together the following code:

<script type="text/javascript">
    function LoginPrep() {
        var txtUserName = document.getElementById('<%= LoginControl.FindControl("UserName").ClientID %>');
        var txtPassword = document.getElementById('<%= LoginControl.FindControl("Password").ClientID %>');
        var hdUserNm = document.getElementById("hdUserNm");
        var hdPasswrd = document.getElementById("hdPasswrd");
        hdPasswrd.Value = txtPassword.Value;
        hdUserNm.Value = txtUserName.Value;
        txtUserName.Value = '';
        txtPassword.Value = '';
    }
</script>

This function is called by onClientClick event of the login button and the logging in itself is dealt with by the on click event of the button instead of the built in functions of the login control which gets the input from the hdPasswrd and hdUserNm which are hidden fields. The login works but the Do you want to save the password message still shows and if I press yes it saves it. Why is this not working?

Edit: I did debugging and see that the hidden fields do not receive the values from the UserName and Password text boxes and the login control UserName and Password are still populated. What's wrong?

Was it helpful?

Solution

The problem is control.Value with the capitol V. I changed it to value with a small v and I recieve the values. That's very strange because the capitol V went in by the VS 2010 intellisense.

That fixed that problem but because I was using the asp.net Login control when the text boxes turn blank the post back didn't take place. Since I'm using a template and my own button and my own authentication I really don't need the Login control so I made it all without the Login control and now it's working withuot showing the save passwword message and doesn't save or auto complete.

My final javascript code is:

function LoginPrep() {
        var txtUserName = document.getElementById('<%= UserName.ClientID %>');
        var txtPassword = document.getElementById('<%= Password.ClientID %>');
        var hdUserNm = document.getElementById("hdUserNm");
        var hdPasswrd = document.getElementById("hdPasswrd");
        hdPasswrd.value = txtPassword.value;
        hdUserNm.value = txtUserName.value;
        txtUserName.value = '';
        txtPassword.value = '';
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top