Hello everyone,
Please see the line in bold below. I am trying to redirect the user to the Default.aspx page if the query from the typed data set (Criteria) returns at least a row. However, I am putting in usernames and passwords that do not exist in the 'People' table and it still goes true and redirects to the Default.aspx page. I know that the query works because I have tested it out. Either way, if I enter in a valid login account or invalid login account it is coming back true. If I put in > 1 instead of > 0 then it would redirect me to the SignInError.aspx. I dont' know why it's counting an invalid entry as one row. Am I doing something wrong? Please help. Thank you.
Kathy
code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using LoginInfoTableAdapters;
namespace LoginTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;
private void Page_Load(object sender, System.EventArgs e)
{
}
protected void cmdSubmit_Click(object sender, System.EventArgs e)
{
string UserName = string.Empty;
string Password = string.Empty;
UserName = ((TextBox)Login1.FindControl("UserName")).Text;
Password = ((TextBox)Login1.FindControl("Password")).Text;
if (Page.IsValid)
{
tblPeopleTableAdapter LoginAdapter = new tblPeopleTableAdapter();
LoginInfo.tblPeopleDataTable Criteria =
LoginAdapter.GetDataBy(UserName, Password);
// Redirect if we succeeded
if (Criteria.Rows.Count > 0)
{
Response.Redirect("Default.aspx");
}
else
{
Response.Redirect("SignInError.aspx");
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Please see the line in bold below. I am trying to redirect the user to the Default.aspx page if the query from the typed data set (Criteria) returns at least a row. However, I am putting in usernames and passwords that do not exist in the 'People' table and it still goes true and redirects to the Default.aspx page. I know that the query works because I have tested it out. Either way, if I enter in a valid login account or invalid login account it is coming back true. If I put in > 1 instead of > 0 then it would redirect me to the SignInError.aspx. I dont' know why it's counting an invalid entry as one row. Am I doing something wrong? Please help. Thank you.
Kathy
code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using LoginInfoTableAdapters;
namespace LoginTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;
private void Page_Load(object sender, System.EventArgs e)
{
}
protected void cmdSubmit_Click(object sender, System.EventArgs e)
{
string UserName = string.Empty;
string Password = string.Empty;
UserName = ((TextBox)Login1.FindControl("UserName")).Text;
Password = ((TextBox)Login1.FindControl("Password")).Text;
if (Page.IsValid)
{
tblPeopleTableAdapter LoginAdapter = new tblPeopleTableAdapter();
LoginInfo.tblPeopleDataTable Criteria =
LoginAdapter.GetDataBy(UserName, Password);
// Redirect if we succeeded
if (Criteria.Rows.Count > 0)
{
Response.Redirect("Default.aspx");
}
else
{
Response.Redirect("SignInError.aspx");
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}