title: Check for empty textboxes using C# function
body: <p>I have written a function to check if any textboxes on a form are blank. 
  It currently works if I add it to the TextBox 'leave' event. </p>
  
  <p>I tried adding it to a button click event but it gives an error (<code>NullReferenceException unhandled</code>).</p>
  
  <p>Below is the code: </p>
  
  <pre><code>public void inputBlank(object sender, EventArgs e)
      {
          TextBox userInput;
          userInput = sender as TextBox;
          userTextBox = userInput.Text;
          string blankBoxName = userInput.Name;
          string blankBox = blankBoxName.Remove(0,3);
  
          if (userTextBox == "")
          {
              errWarning.SetError(userInput, "Please enter a value for " + blankBox);
              userInput.Focus();
          }
          else
          {
              errWarning.SetError(userInput, "");
          }
      }
  </code></pre>
  
  <p>Just wondering if you could advise me how to fix it.</p>
  
  <p>Many thanks.</p>