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 September 19th, 2011, 05:06 PM
Authorized User
 
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default Validating Phone Numbers (from chapter 9)

Ok so this is driving me insane right now.

I am currently on page 313 at the How It Works and mine is not working like the book says it should.

When I leave all fields blank and click Send I get the popup with the information to:

Enter Name
Enter an e-mail address
Confirm e-mail address
Enter a comment

I do not get the message to Enter a home or business phone number.

I only get an error on this if all other fields are filled in correctly and submitted and then I only get the *.

I have compared my code to the downloaded code and checked all spelling and capitalization and just can not figure it out. Below I will submit my code snippets for review. Thank you for your time!

javascript:
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 != '') 
     {
      args.IsValid = true;
     }
     else 
     {
      args.IsValid = false;
     }
    }
</script>
Code Behind:
Code:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (!string.IsNullOrEmpty(PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }
Source from Table:
Code:
<asp:CustomValidator ID="CustomValidator1" runat="server" 
                ClientValidationFunction="ValidatePhoneNumbers" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Enter your home or business phone number" 
                onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
 
Old September 19th, 2011, 06:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're missing .value after phoneBusiness in the client JavaScript.

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!
The Following 2 Users Say Thank You to Imar For This Useful Post:
SamuelMSr (September 19th, 2011)
 
Old September 19th, 2011, 06:12 PM
Authorized User
 
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

WOW!! After all that time staring at it you would think I would have seen that.

Thank you very much!
 
Old September 19th, 2011, 07:11 PM
Authorized User
 
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

I wish people would quit looking at this.....

I guess we all have those "moments"....
 
Old September 20th, 2011, 02:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That's why a second pair of eyes is always so useful.... ;-)

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
ch2 contacts w/ phone numbers jfgass83 BOOK: Beginning Android Application Development 0 September 13th, 2011 01:08 PM
Chapter 9 Validating Phone Numbers shilohcoder BOOK: Beginning ASP.NET 4 : in C# and VB 3 March 5th, 2011 06:12 AM
Regular expression for phone numbers [both U.S. an kamii47 BOOK: Beginning Regular Expressions 0 September 8th, 2007 03:08 AM
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.