brendanlefavre
asked on
Nested IF statement help
Under my button click event, I have several if statements. I'm having trouble with the evaluation of the passwordLastSet. Even if it has been more than 24 hours, it goes directly to the else statement that the password has been set less than 24 hours ago.
Cheers,
Brendan
Cheers,
Brendan
protected void btnSubmit_Click(object sender, EventArgs e)
{
System.Guid guid = Guid.NewGuid();
logInfo.IPaddress = "need to add IP address method";
if (txtUser.Text != string.Empty)
{
string username = txtUser.Text.ToString();
if (DateTime.Now.Subtract(passwordLastSet).TotalHours < 24)
{
if (UserExists(FindName(username)))
{
logInfo.userName = txtUser.Text.ToString();
logInfo.TrackingID = guid;
logInfo.requestType = "Request Password";
logInfo.email = eMailAddress.ToString();
logInfo.InsertRequest();
lblStatus.Text = "all is good";
}
else
{
lblStatus.Text = "The user does not exists";
logInfo.errorType = lblError.Text.ToString();
logInfo.userName = txtUser.Text.ToString();
logInfo.TrackingID = guid;
logInfo.InsertRequestError();
}
// return a message that the time since last reset has been less than 24 hours
}
else
{
lblStatus.Text = "the time has been less than 24 hours";
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
your sample worked, and helped me achieve the result I was looking for. Also I was able to adapt this to a few other areas of my project.
DateTime.Now.Subtract(pass
then try to convert that value to integer
by using
convert.toint16(DateTime.N
then check it