I can not say, but I believe that in most browsers put themselves in the tag <form>
should work:
<form action="baz.aspx" method="post" autocomplete="off">
Of course regardless of this, this is something of user control, is a facilitator, I think it should be user choice whether or not he wants to save.
Of course there are alternative solutions that might solve the problem, like using a form
false combined with Ajax, ie would probably not even use asp:TextBox runat=server
for example (should not be within form
):
<div id="meu-form" data-url="foo.aspx" data-location="/dashboard/">
<input name="login" autocomplete="off">
<input name="pass" autocomplete="off">
<button class="logar">Logar</button>
</div>
And in Ajax it would look like this:
var form = document.getElementById('meu-form'),
requesting = false;
actLogon.onclick = function() {
if (requesting) return;
//Bloqueia as requisições enquanto estiver logando
requesting = true;
var action = form.dataset.url;
var loc = form.dataset.location;
var actLogon = form.querySelector('button.logar');
var login = form.querySelector('login');
var pass = form.querySelector('pass');
//Variaveis que vão para o servidor
var variaveis = [
"login=" + encodeURIcomponent(login),
"pass=" + encodeURIcomponent(pass)
].join("&");
//Ajax
var oReq = new XMLHttpRequest;
oReq.open("POST", action, true);
//Função assíncrona que aguarda a resposta
oReq.onreadystatechange = function()
{
if (oReq.readyState === 4) {
if (oReq.status === 200) {
if (oReq.responseText === "sucesso") {
window.location.replace(loc);
} else {
alert("Erro: " + oReq.responseText);
}
} else {
alert("Erro: " + oReq.status);
}
actLogon = false;
}
};
//Envia a requisição, mas a resposta fica sendo aguardada em Background
oReq.send(variaveis);
};
Explaining the code:
The <div id="meu-form" data-url="foo.aspx" data-location="/dashboard/">
will take the place of the form
The data-url="foo.aspx"
must contain the URL value that will be used only for the ajax
The data-location="/dashboard/"
must contain the target URL, that is the screen after the user is logged in
As variaveis
should contain the keys and values that will pick up the Ajax page (foo.aspx
is only one example)
var variaveis = [
"login=" + encodeURIcomponent(login),
"pass=" + encodeURIcomponent(pass)
].join("&");
Your aspx should return only the text sucesso
in the response to Ajax, if the login was correct:
if (oReq.responseText === "sucesso") {
window.location.replace(loc);
} else {
alert("Erro: " + oReq.responseText);
}
Otherwise it will display the alert
with an error message, which you can customize.
In the foo.aspx
(regardless of the name you give), should look something like:
context.Response.ContentType = "text/plain";
var login = context.Request.Form["login"];
var pass = context.Request.Form["pass"];
//Faz o login aqui
if (/*Se o login estiver correto*/) {
context.Response.Write("sucesso");
} else {
context.Response.Write("Erro");
}
context.Response.End();
I’m not sure if it works, but you’ve tried setting the attributes
TextMode="Password"
,EnableViewState="false"
andAutoComplete="off"
in the ASP field?– Gomiero
I didn’t try, but I took the test now, and it didn’t work either.
– Mariana
Would that be? How to disable Chrome Pop-UP to save passwords?
– Marconi