title: C# Winforms Error handling for dynamically created textboxes
body: <p>I have two textboxes that are created dynamically created on load. The user can click the add button which adds two new text boxes to the interface each time. When these textboxes are added they are also added to a list. I am trying to add error handling to my project to make sure every textbox is filled out before the user can click save. If the text boxes are empty a message box should show : Please fill out all message boxes.
  If the textboxes are filled out a message box should show: Are you sure you want to make this change?
  If the user clicks yes the changes should be saved and the message box "Changes saved " should show
  If the user clicks no then the message box should disappear and the changes not saved.
  The message boxes are not acting the way I expected
  Here is what I have so far:</p>
  
  <p>Create the text boxes:</p>
  
  <pre><code> private void ADDUserInfo(int rowCount, string password = "", string username = "")
              var Password = new TextBox();
              Password.Text = password;
              Password.Name = "Password" + rowCount;
  
              var Username = new TextBox();
              Username.Text = username;
              Username.Name = "Username" + rowCount;
  
              CaeUsersPanel.Controls.Add(Username);
              CaeUsersPanel.Controls.Add(Password);
  
              UsernameTextBoxes.Add(Username);
              PasswordTextboxes.Add(Password);
              }
  </code></pre>
  
  <p>Global declaration of the lists of textboxes:</p>
  
  <pre><code>List&lt;TextBox&gt; UsernameTextBoxes = new List&lt;TextBox&gt;();
  List&lt;TextBox&gt; AliasTextBoxes = new List&lt;TextBox&gt;();
  List&lt;TextBox&gt; PasswordTextboxes = new List&lt;TextBox&gt;();
  </code></pre>
  
  <p>The save button: </p>
  
  <pre><code> for (int i = 0; i &lt; UsernameTextBoxes.Count; i++)
              {
                  var userName = UsernameTextBoxes[i];
                  var password = PasswordTextboxes[i];
                  _config.Environment.Users.User.Add(new EnvironmentUsersUser() { alias = aliasName.Text, userName = userName.Text, password = password.text, toDisplay = true });
  
              }
  
              configmgr.Serilize&lt;Config&gt;(_configurationTabData._objectSources.getEnviromentFileName, _config);
  
  
              for (int i = 0; i &lt; UsernameTextBoxes.Count; i++)
              {
                  var userName = UsernameTextBoxes[i];
                  var password = PasswordTextboxes[i];
                  if (aliasName.Text == "" || userName.Text == "" || password.Text == "")
                  {
                      MessageBox.Show("All fields are required!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                  }
                  else
                  {
                    DialogResult result = MessageBox.Show("Are you sure you want to make these changes", "Warning", MessageBoxButtons.YesNo);
              if (result == DialogResult.Yes)
              {
                  configmgr.Serilize&lt;Config&gt;(_configurationTabData._objectSources.getEnviromentFileName, _config);
                  MessageBox.Show("Changes Saved")
              }
             }
  
              }
  </code></pre>