M
Mike P
I have a form with a Serial No and Pin text box which are validated with
required field validators. Once they are validated my code goes to a
btn_Click event and if Page.IsValid then checks to see if the Serial No
and Pin is in a database table.
My problem is that once the user has entered details in the Serial No
and Pin boxes making Page.IsValid true, when I clear these text boxes
Page.IsVaild still seems to be true, because my Page.IsValid code still
executes and tells the user that their Serial No/Pin does not exist, as
well as telling the user that they need to enter stuff in the text
boxes. This is my code :
public void btnSubmit_Click(object sender, EventArgs e)
{
feedbackLabel.Text = "";
if (Page.IsValid)
{
string strSerialNumber, strPinNumber, strSQL;
strSerialNumber = SerialNumber.Text.Trim();
strPinNumber = PinNumber.Text.Trim();
strSQL = "SELECT * FROM purple_cards WHERE serial = '" +
strSerialNumber + "' AND PIN = '" + strPinNumber + "'";
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strConnect"]);
SqlDataReader objDataReader = null;
SqlCommand objCommand = new SqlCommand(strSQL,
objConnection);
try
{
objConnection.Open();
objDataReader = objCommand.ExecuteReader();
if (objDataReader.Read() == true)
{
feedbackLabel.Text = "Record found";
}
else
{
feedbackLabel.Text = "Record not found";
}
}
catch
{
feedbackLabel.Text = "Connection failed to open
successfully";
}
}
}
Has anybody else had this problem?
Any help would be really appreciated.
Mike
required field validators. Once they are validated my code goes to a
btn_Click event and if Page.IsValid then checks to see if the Serial No
and Pin is in a database table.
My problem is that once the user has entered details in the Serial No
and Pin boxes making Page.IsValid true, when I clear these text boxes
Page.IsVaild still seems to be true, because my Page.IsValid code still
executes and tells the user that their Serial No/Pin does not exist, as
well as telling the user that they need to enter stuff in the text
boxes. This is my code :
public void btnSubmit_Click(object sender, EventArgs e)
{
feedbackLabel.Text = "";
if (Page.IsValid)
{
string strSerialNumber, strPinNumber, strSQL;
strSerialNumber = SerialNumber.Text.Trim();
strPinNumber = PinNumber.Text.Trim();
strSQL = "SELECT * FROM purple_cards WHERE serial = '" +
strSerialNumber + "' AND PIN = '" + strPinNumber + "'";
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strConnect"]);
SqlDataReader objDataReader = null;
SqlCommand objCommand = new SqlCommand(strSQL,
objConnection);
try
{
objConnection.Open();
objDataReader = objCommand.ExecuteReader();
if (objDataReader.Read() == true)
{
feedbackLabel.Text = "Record found";
}
else
{
feedbackLabel.Text = "Record not found";
}
}
catch
{
feedbackLabel.Text = "Connection failed to open
successfully";
}
}
}
Has anybody else had this problem?
Any help would be really appreciated.
Mike