0
I need to open a modal when the password or user are incorrect, it will be on Else .. but does not open the modal
protected void bntLogar_Click(object sender, EventArgs e)
{
Registrar criptografia = new Registrar();
if (Login.logarUsuario(txtUser.Text, criptografia.CriptografiaMD5(txtSenha.Text)))
{
//Cria um cookie do lado do servidor
HttpCookie cookie = new HttpCookie("estado", "conectado");
//Define a validade do cookie (10 dias a partir de hoje)
cookie.Expires = DateTime.Now.AddMonths(12);
//Envia o cookie para o cliente
Response.Cookies.Set(cookie);
//Redireciona para a pagina inicial
Response.Redirect("Admin.aspx");
//fortawsome
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
}
}
And I put inside the tag the Javascript code
<script type="text/javascript">
function openModal() {
$('#myModal').modal('show');
}
</script>
Modal code
<div class="modal fade" id="modalLogin" runat="server" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4>Warning</h4>
</div>
<div class="modal-body">
<p>Watch out! Your about to be locked out.</p>
</div>
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
Thanks for the feedback. I tested the code but it didn’t work.. still doesn’t show the modal when it doesn’t authenticate the user.
– Gabriel Bernardone
Does the page . aspx (layout or master) have an associated Scriptmanager? I edited the answer.
– Diogo
True, that was missing. I put logos after
<form id="form1" runat="server">
but it didn’t work. I put the modal code in the post.. I really have no idea why it doesn’t work– Gabriel Bernardone
I edited the answer again, I suppose that’s the final problem.
– Diogo
Thank you very much for your attention.. I applied the necessary corrections but it still doesn’t work.. nothing from modal open.. I really don’t know what’s going on.
– Gabriel Bernardone
Remove the "runat=server" tag from the modal, this changes the ID to an automatically generated one. Let’s hope it’s the last thing
– Diogo