I have a login box, made with jquery with text boxes and then an asp:button, that validates and makes the sessions, like in the code.
I have made that a label appears when the username and password is wrong and you click the asp:button, but because of the post back the login box disappears.
protected void Button1_Click(object sender, EventArgs e)
{
Connectons etc...
cmd.CommandText = "SELECT * FROM Users WHERE Email = @email AND password = @pass";
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = username.Text;
cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = password.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
Session["user_id"] = reader["user_id"];
Session["username"] = reader["Username"];
Session["name"] = reader["Name"];
Session["password"] = reader["Password"];
Session["LoggedIn"] = true;
Session["role"] = reader["Role_id"];
if (Convert.ToInt32(reader["Role_id"]) == 1)
{
Response.Redirect("Admin/default.aspx");
}
else
{
Response.Redirect("default.aspx");
}
}
else
{
Label1.Text = "Login is wrong";
}
conn.Close();
}
How do i make the button not post back if the login is wrong?
<a id="modal_trigger" href="#modal" class="btn btn-default">Log ind</a>
<div id="modal" class="popupContainer" style="display: none;"> </div>
$("#modal_trigger").leanModal({
top: 100,
overlay: 0.6,
closeButton: ".modal_close"
});