You don't even need an if here:
lbl_nameError.Visible = txt_name != query.Name;
lbl_lastNameError.Visible = txt_lastname != query.LastName;
But if you want to use an if:
if (txt_name!=query.Name)
{
lbl_nameError.Visible = true;
}
else
{
lbl_nameError.Visible = false;
}
if (txt_lastname != query.LastName)
{
lbl_lastNameError.Visible = true;
}
else
{
lbl_lastNameError.Visible = false;
}