emaduddeen
Well-known member
- Joined
- May 5, 2010
- Messages
- 171
- Location
- Lowell, MA & Occasionally Indonesia
- Programming Experience
- Beginner
Hi Everyone,
I have a button with DialogResult OK set.
I'm using the following code to try and do validation:
This code was originally in the Click event of the button but in the Click event I discovered e.Cancel does not work so I put the code in the Validating event.
The problem I now face is that the code never gets touched because the DialogResult OK is executing before the Validation event is touched.
Is there a way to stop DialogResult OK from executing based on my code?
Thanks.
Truly,
Emad
I have a button with DialogResult OK set.
I'm using the following code to try and do validation:
VB.NET:
Private Sub ButtonSaveChanges_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ButtonSaveChanges.Validating
If String.IsNullOrEmpty(EditBoxLastName.Text) Then
MessageBox.Show("Please enter a customer name.", _
"Entry Error", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
e.Cancel = True
Else
If SaveCustomerToDatabase() = True Then
SaveCustomerRelativeToDatabase()
End If
End If
End Sub
This code was originally in the Click event of the button but in the Click event I discovered e.Cancel does not work so I put the code in the Validating event.
The problem I now face is that the code never gets touched because the DialogResult OK is executing before the Validation event is touched.
Is there a way to stop DialogResult OK from executing based on my code?
Thanks.
Truly,
Emad