I really need halp on this one.
I am trying to display a message box for mandatory fields only. However the message box still appears for the optional fields such as phone, comments and email when I click Add Student. Can any one give me any advice on excluding the optinal fields. I have entered the piece of code that am working on for this for this section.
private void btnAddNewStud_Click(object sender, System.EventArgs e)
{
foreach(System.Windows.Forms.Control aControl in this.Controls)
{
if(aControl is System.Windows.Forms.TextBox & aControl.Text
== "")
{
MessageBox.Show("Please ensure that the First Name, Last Name, Address and Course details are entered");
aControl.Focus();
return;
if(aControl is System.Windows.Forms.TextBox & aControl.Name == "txtEmail")
{
return;
}
}
}
END: I have tried using a 2nd 'If' statement to test when the email text box is reached and to return straight away but this doesnt seem to work.
Any help would be great