Check if TextBox is empty and return MessageBox?

后端 未结 8 1359
谎友^
谎友^ 2020-12-23 22:19

I made this statement to check if TextBox is empty, but the MessageBox always shows up wether the TextBox is empty or not.

    private void NextButton_Click         


        
8条回答
  •  心在旅途
    2020-12-23 22:37

    Becasue is a TextBox already initialized would be better to control if there is something in there outside the empty string (which is no null or empty string I am afraid). What I did is just check is there is something different than "", if so do the thing:

     if (TextBox.Text != "") //Something different than ""?
            {
                //Do your stuff
            }
     else
            {
                //Do NOT do your stuff
            }
    

提交回复
热议问题