Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2011, 04:39 PM
Registered User
 
Join Date: Feb 2011
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Exclamation Chapter 9 Validating Phone Numbers

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
 
Old March 3rd, 2011, 10:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you also post the markup that shows where you hookup the client valiator functiion

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 4th, 2011, 09:56 AM
Registered User
 
Join Date: Feb 2011
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 9 Validating Phone numbers

Thank you:

[code]
<asp:CustomValidator ID="CustomValidator2" runat="server"
ClientValidationFunction="ValidatePhoneNumbers"
CssClass="ErrorMessage"
Display="Dynamic" ErrorMessage="Enter your home or business phone"
>*</asp:CustomValidator>
[/]

Is this the code you need?
 
Old March 5th, 2011, 06:12 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Took me some time to figure out what the problem was as things looked right to me at first. Turns out, you got your casing wrong:

args.isValid

should be

args.IsValid

wit a capital I.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help retrieving Contact phone numbers androidNewbie BOOK: Professional Android 2 Application Development 0 October 12th, 2010 08:24 AM
Regular expression for phone numbers [both U.S. an kamii47 BOOK: Beginning Regular Expressions 0 September 8th, 2007 03:08 AM
trying to make a custom label for phone numbers... thenoseknows ASP.NET 2.0 Professional 2 August 22nd, 2006 06:07 PM
formatting phone numbers xslt_student XSLT 0 August 7th, 2006 04:10 PM
U.S versus International Phone Numbers bph Access 6 February 19th, 2004 05:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.