Hello,
I am using the following code to validate the phone number fields of the contactform control. In the book on page 313 it shows the validation summary and messagebox as containing the error message for phone numbers along with the other empty fields (upon pressing send). However, I am not seeing this functionality; rather, if I leave all the fields blank, I only receive the error messages for the name, email fields and comment fields, no message for the phone number fields. If I fill in the other fields and leave the phone number fields blank and press send, then I get the error message for the phone numbers. I need to be able to tell my students how to fix this! Thank you for the help.
Code:
<script type="text/javascript">
function ValidatePhoneNumbers(source, args)
{
var phoneHome = document.getElementById('<%= PhoneHome.ClientID %>');
var phoneBusiness = document.getElementById('<%= PhoneBusiness.ClientID %>');
if (phoneHome.value != '' || phoneBusiness.value != '')
{
args.isValid = true;
}
else
{
args.isValid = false;
}
}
</script>
<table class="style1" runat="server" id="FormTable">
Code from code behind of contactform control
Code:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator2.ServerValidate
If Not String.IsNullOrEmpty(PhoneHome.Text) Or Not String.IsNullOrEmpty(PhoneBusiness.Text) Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub