private void editStudentButton_Click(object sender, EventArgs e) { EditStudent edit = new EditStudent(student); DialogResult dialog = edit.ShowDialog(this); if (dialog != DialogResult.OK) { return; } else { // Make this local var to prevent "marshal-by-reference" classes - https://stackoverflow.com/questions/4178576/accessing-a-member-on-form-may-cause-a-runtime-exception-because-it-is-a-field-o int newAlps = edit.newAlps; Dictionary <string, string> formData = new Dictionary <string, string> { { "forename", edit.newForename }, { "surname", edit.newSurname }, { "alps", newAlps.ToString() }, }; if (edit.isNewUsername) { formData.Add("username", edit.newUsername); } APIHandler.UpdateStudent(student, formData); MessageBox.Show(edit.newForename + "'s account has been edited."); this.studentPanelNeedsRefresh = true; this.Close(); } }