Hi, is it ok to use an if condition as a presence check, this is my code -

if (textBox1 != null)
            {
                MessageBox.Show("Dont Leave Blank");
     
            }

            else

                MessageBox.Show("Successfully added");

my code runs however no matter if there is text in textbox1 or if its left empty it shows "Dont Leave Blank" any suggestions?

thanks

Wrong. You have to put a property of a textbox control on the end of it to check it:

if(textBox.Text != String.Empty)
{
   //not empty (not null, even empty and null are not the same things)
}
else
{
   //empty!
}
This question has already been answered. Start a new discussion instead.