Tony

Tony

  • NA
  • 30
  • 0

Where/How to validate fields on Form2

Oct 29 2009 2:59 PM

I am new to C# but have developed an application that worked until the need came up for two additional fields of information (maybe more later). Because of the way the app is structured, I decided to ask for these two fields in a second form (Form2) using a dialog box. This seems to work well and am able to retrieve the two textboxes and include with fields from Form1 to develop a transaction and log entry.  However, I have a problem.

I am not sure where I should check that both fields on Form2 have been filled. I have tried checking for blank fields in both forms but although I can generate a message telling the user that both fields are required, I cannot seem to get Form2 to redisplay for the user to fill in the fields. The if/else code continues to the next step which happens to be generating the transaction in Form1.   I want it to - if the either field is empty, then display a message and don't leave Form2 until they are filled or the form canceled.   Where is the best place to do this check and redisplay the form until the user fills in both fields and hits OK or hits cancel?   How do I do it?     I have tried various similar ways found in postings using Google and none have worked.
I have similar code in Form1 to check for valid and required fields and it works just fine.  Nothing happens until the validations are satisfied.   Why not in Form2.    
Thanx in advance for any help. This site has been a big help in working through learning C#.

Answers (6)