Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 12th, 2009, 03:03 PM
Registered User
 
Join Date: May 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 Custom validator - client siden not working; popup for phone not showing

Hello,
I am going through the Try it Now section on pages 302 - 305 and have encountered two problems.
1. The error message and asterix for the phone number don't display until i have filled in all the other fields that have validators- ie. my page never looks like your image in figure 9-8. Home and business phone number and asterix do not ever show at same time as the others. The book does not say to include a required validator on home phone, so I did not add that - and I suppose I would not want to add one because I want either phone number filled.

2. When I switch the validation summary to show message box, it never shows the message box for the phone number validation - only for the others.

Am I missing something?

My code follows:
ContactForm.ascx
Code:
<%@ControlLanguage="C#"AutoEventWireup="true"CodeFile="ContactForm.ascx.cs"Inherits="Controls_ContactForm" %>
<scripttype="text/javascript">
function ValidatePhoneNumbers(source, args) {
var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
var txtPhoneBusiness = document.getElementById('<%= txtPhoneBusiness.ClientID %>');
if (txtPhoneHome.value != '' || txtPhoneBusiness != '') 
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
<table>
<tr>
<tdcolspan="3">
Please fill in this form to get in touch with us.</td>
</tr>
<tr>
<td>
Your name</td>
<td>
<asp:TextBoxID="txtName"runat="server"Width="217px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="txtName"ErrorMessage="Please enter your name"Display="Dynamic">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Email address</td>
<td>
<asp:TextBoxID="txtEmailAddress"runat="server"Width="266px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="txtEmailAddress"Display="Dynamic"ErrorMessage="Please enter an email address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlToValidate="txtEmailAddress"Display="Dynamic"ErrorMessage="Please enter a valid email address"ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Confirm email address</td>
<td>
<asp:TextBoxID="txtEmailAddressConfirm"runat="server"Width="269px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator4"runat="server"ControlToValidate="txtEmailAddressConfirm"Display="Dynamic"ErrorMessage="Please confirm the email address">*</asp:RequiredFieldValidator>
<asp:CompareValidatorID="CompareValidator1"runat="server"ControlToCompare="txtEmailAddress"ControlToValidate="txtEmailAddressConfirm"Display="Dynamic"ErrorMessage="Please retype the email address">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td>
Home Phone</td>
<td>
<asp:TextBoxID="txtPhoneHome"runat="server"></asp:TextBox>
</td>
<td>
<asp:CustomValidatorID="CustomValidator1"runat="server"ClientValidationFunction="ValidatePhoneNumbers"Display="Dynamic"ErrorMessage="Please enter home or business phone number"onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Business Phone</td>
<td>
<asp:TextBoxID="txtPhoneBusiness"runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Comments</td>
<td>
<asp:TextBoxID="txtComments"runat="server"Height="62px"TextMode="MultiLine"Width="273px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="txtComments"Display="Dynamic"ErrorMessage="Please enter a comment">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:ButtonID="btnSend"runat="server"Text="Send"/>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<tdcolspan="3">
<asp:ValidationSummaryID="ValidationSummary1"runat="server"/>
</td>
</tr>
</table>
ContactForm.ascx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassControls_ContactForm : System.Web.UI.UserControl
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPhoneHome.Text != string.Empty || txtPhoneBusiness.Text != string.Empty)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}

Last edited by nkem; May 12th, 2009 at 03:35 PM..
Reply With Quote
  #2 (permalink)  
Old May 12th, 2009, 04:53 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi nkem

Can you pleae post your code again and then use the Remove Text Formatting button on the toolbar on the editor? Due to a bug in this forum, all spaces get removed when posting color coded code. Makes it easier for me to see what's going on.

On top of that, can you also post the final HTML in the browser? E.g., a the result of View Source in IE or Firefox?

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!
Reply With Quote
  #3 (permalink)  
Old May 12th, 2009, 05:39 PM
Registered User
 
Join Date: May 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sure. Here is the code again:
ContactForm.ascx
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<script type="text/javascript">
function ValidatePhoneNumbers(source, args) {
var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
var txtPhoneBusiness = document.getElementById('<%= txtPhoneBusiness.ClientID %>');
if (txtPhoneHome.value != ' ' || txtPhoneBusiness != ' ') 
{
args.IsValid = true;
}
else 
{
args.IsValid = false;
}
}
</script>
<table runat="server" id="FormTable">
<tr>
<td colspan="3">
Please fill in this form to get in touch with us.</td>
</tr>
<tr>
<td>
Your name</td>
<td>
<asp:TextBox ID="txtName" runat="server" Width="217px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
ControlToValidate="txtName" ErrorMessage="Please enter your name" 
Display="Dynamic">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Email address</td>
<td>
<asp:TextBox ID="txtEmailAddress" runat="server" Width="266px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
ControlToValidate="txtEmailAddress" Display="Dynamic" 
ErrorMessage="Please enter an email address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
ControlToValidate="txtEmailAddress" Display="Dynamic" 
ErrorMessage="Please enter a valid email address" 
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Confirm email address</td>
<td>
<asp:TextBox ID="txtEmailAddressConfirm" runat="server" Width="269px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
ControlToValidate="txtEmailAddressConfirm" Display="Dynamic" 
ErrorMessage="Please confirm the email address">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" 
ControlToCompare="txtEmailAddress" ControlToValidate="txtEmailAddressConfirm" 
Display="Dynamic" ErrorMessage="Please retype the email address">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td>
Home Phone</td>
<td>
<asp:TextBox ID="txtPhoneHome" runat="server"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server" 
ClientValidationFunction="ValidatePhoneNumbers" Display="Dynamic" 
ErrorMessage="Please enter home or business phone number" 
onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Business Phone</td>
<td>
<asp:TextBox ID="txtPhoneBusiness" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Comments</td>
<td>
<asp:TextBox ID="txtComments" runat="server" Height="62px" TextMode="MultiLine" 
Width="273px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
ControlToValidate="txtComments" Display="Dynamic" 
ErrorMessage="Please enter a comment">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Send" onclick="btnSend_Click" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</td>
</tr>
</table>
<asp:Label ID="lblMessage" runat="server" Text="Message Sent" Visible="False"></asp:Label>
<p>
&nbsp;</p>

Contactform.ascx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class Controls_ContactForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPhoneHome.Text != string.Empty || txtPhoneBusiness.Text != string.Empty)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void btnSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = System.IO.File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", txtName.Text);
mailBody = mailBody.Replace("##Email##", txtEmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", txtPhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", txtPhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", txtComments.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("a@a.org", "Sender Name here");
myMessage.To.Add(new MailAddress("a@a.org", "Receiver Name here"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
lblMessage.Visible = true;
FormTable.Visible = false;
}
}
}

Browser output
Code:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
 Contact Us
</title>
<link href="../App_Themes/Monochrome/Monochrome.css" type="text/css" rel="stylesheet" /><style type="text/css">
 .ctl00_Menu1_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
 .ctl00_Menu1_1 { text-decoration:none; }
 .ctl00_Menu1_2 {  }
 .ctl00_Menu1_3 { border-style:none; }
 .ctl00_Menu1_4 {  }
 .ctl00_Menu1_5 { border-style:none; }
 .ctl00_Menu1_6 {  }
 .ctl00_Menu1_7 { border-style:none; }
 .ctl00_Menu1_8 {  }
 .ctl00_Menu1_9 { border-style:none; }
 .ctl00_Menu1_10 {  }
 .ctl00_Menu1_11 { border-style:none; }
 .ctl00_Menu1_12 {  }
</style></head>
<body>
  <form name="aspnetForm" method="post" action="Contact.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIwMDgzODYxMzcPZBYCZg9kFgICAw9kFggCAw88KwANAgAPFgIeC18hRGF0YUJvdW5kZ2QMFCsABQUPMDowLDA6MSwwOjIsMDozFCsAAhYQHgRUZXh0BQRIb21lHgVWYWx1ZQUESG9tZR4LTmF2aWdhdGVVcmwFDS9EZWZhdWx0LmFzcHgeB1Rvb2xUaXAFEkdvIHRvIHRoZSBob21lcGFnZR4HRW5hYmxlZGceClNlbGVjdGFibGVnHghEYXRhUGF0aAUNL2RlZmF1bHQuYXNweB4JRGF0YUJvdW5kZ2QUKwACFhAfAQUHUmV2aWV3cx8CBQdSZXZpZXdzHwMFFS9SZXZpZXdzL0RlZmF1bHQuYXNweB8EBR5SZXZpZXdzIHB1Ymxpc2hlZCBvbiB0aGlzIHNpdGUfBWcfBmcfBwUVL3Jldmlld3MvZGVmYXVsdC5hc3B4HwhnFCsAAwUHMDowLDA6MRQrAAIWEB8BBQhCeSBHZW5yZR8CBQhCeSBHZW5yZR8DBRgvUmV2aWV3cy9BbGxCeUdlbnJlLmFzcHgfBAUcQWxsIFJldmlld3MgR3JvdXBlZCBieSBHZW5yZR8FZx8GZx8HBRgvcmV2aWV3cy9hbGxieWdlbnJlLmFzcHgfCGdkFCsAAhYQHwEFC0FsbCBSZXZpZXdzHwIFC0FsbCBSZXZpZXdzHwMFES9SZXZpZXdzL0FsbC5hc3B4HwQFC0FsbCBSZXZpZXdzHwVnHwZnHwcFES9yZXZpZXdzL2FsbC5hc3B4HwhnZBQrAAIWEB8BBQVBYm91dB8CBQVBYm91dB8DBRMvQWJvdXQvRGVmYXVsdC5hc3B4HwQFD0Fib3V0IHRoaXMgU2l0ZR8FZx8GZx8HBRMvYWJvdXQvZGVmYXVsdC5hc3B4HwhnFCsAAwUHMDowLDA6MRQrAAIWEh8CBQpDb250YWN0IFVzHwhnHghTZWxlY3RlZGcfAQUKQ29udGFjdCBVcx8DBRMvQWJvdXQvQ29udGFjdC5hc3B4HwVnHwZnHwQFCkNvbnRhY3QgVXMfBwUTL2Fib3V0L2NvbnRhY3QuYXNweGQUKwACFhAfAQUIQWJvdXQgVXMfAgUIQWJvdXQgVXMfAwUTL0Fib3V0L0Fib3V0VXMuYXNweB8EBQhBYm91dCBVcx8FZx8GZx8HBRMvYWJvdXQvYWJvdXR1cy5hc3B4HwhnZBQrAAIWEB8BBQVMb2dpbh8CBQVMb2dpbh8DBQsvTG9naW4uYXNweB8EBRdMb2cgaW4gdG8gdGhpcyB3ZWIgc2l0ZR8FZx8GZx8HBQsvbG9naW4uYXNweB8IZ2RkAgcPPCsACQEADxYEHg1OZXZlckV4cGFuZGVkZx4HVmlzaWJsZWhkZAINDxBkZBYBZmQCDw9kFgRmDw8WAh8LZ2QWAgIBDxYCHgRocmVmBRNodHRwOi8vcDJwLndyb3guY29tZAICDw8WAh8LaGRkGAEFC2N0bDAwJE1lbnUxDw9kBRBBYm91dFxDb250YWN0IFVzZOsYUtxnN95Iuq9B9LWzGarlVwn+" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
 
<script src="/WebResource.axd?d=nwCfSGNkSPFOrG20wI0oIQ2&amp;t=633735657308550173" type="text/javascript"></script>
 
<script src="/WebResource.axd?d=gY7Ckx6bU45xZ8mQeX9PfA2&amp;t=633735657308550173" type="text/javascript"></script>
<script src="/WebResource.axd?d=FjiDKKZNLMz10PDGHgfezyU5_yiJ2YwalGjsBKELtiM1&amp;t=633735657308550173" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
<div>
 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCwKVosiECAL5/cOUAgLLs6q2CwLh2NSDAQLX0ZSxDwKcycgfAovVr+EDAu+KjOcCAuWHkq4JAvvto6EDAuGDh/4KugmajVE7li6kwptt+YypFwBpQzE=" />
</div>
  <div id="PageWrapper">
    <div id="Header"><a href="../" class="HeaderLink">Header Goes Here</a>
    </div>
    <div id="MenuWrapper">
      <a href="#ctl00_Menu1_SkipLink"><img alt="Skip Navigation Links" src="/WebResource.axd?d=JitecEm4xhVPKBoriBdZiw2&amp;t=633735657308550173" width="0" height="0" style="border-width:0px;" /></a><table id="ctl00_Menu1" class="ctl00_Menu1_2" cellpadding="0" cellspacing="0" border="0">
 <tr>
  <td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="Go to the homepage" id="ctl00_Menu1n0"><table class="StaticMenuItemStyle ctl00_Menu1_4" cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td style="white-space:nowrap;"><a class="ctl00_Menu1_1 StaticMenuItemStyle ctl00_Menu1_3" href="/Default.aspx" style="border-style:none;font-size:1em;">Home</a></td>
   </tr>
  </table></td><td style="width:3px;"></td><td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="Reviews published on this site" id="ctl00_Menu1n1"><table class="StaticMenuItemStyle ctl00_Menu1_4" cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td style="white-space:nowrap;"><a class="ctl00_Menu1_1 StaticMenuItemStyle ctl00_Menu1_3" href="/Reviews/Default.aspx" style="border-style:none;font-size:1em;">Reviews</a></td>
   </tr>
  </table></td><td style="width:3px;"></td><td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="About this Site" id="ctl00_Menu1n2"><table class="StaticMenuItemStyle ctl00_Menu1_4" cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td style="white-space:nowrap;"><a class="ctl00_Menu1_1 StaticMenuItemStyle ctl00_Menu1_3" href="/About/Default.aspx" style="border-style:none;font-size:1em;">About</a></td>
   </tr>
  </table></td><td style="width:3px;"></td><td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="Log in to this web site" id="ctl00_Menu1n3"><table class="StaticMenuItemStyle ctl00_Menu1_4" cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td style="white-space:nowrap;"><a class="ctl00_Menu1_1 StaticMenuItemStyle ctl00_Menu1_3" href="/Login.aspx" style="border-style:none;font-size:1em;">Login</a></td>
   </tr>
  </table></td>
 </tr>
</table><div id="ctl00_Menu1n1Items" class="ctl00_Menu1_0">
 <table border="0" cellpadding="0" cellspacing="0">
  <tr onmouseover="Menu_HoverDynamic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="All Reviews Grouped by Genre" id="ctl00_Menu1n4">
   <td><table class="DynamicMenuItemStyle ctl00_Menu1_6" cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
     <td style="white-space:nowrap;width:100%;"><a class="ctl00_Menu1_1 DynamicMenuItemStyle ctl00_Menu1_5" href="/Reviews/AllByGenre.aspx" style="border-style:none;font-size:1em;">By Genre</a></td>
    </tr>
   </table></td>
  </tr><tr onmouseover="Menu_HoverDynamic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="All Reviews" id="ctl00_Menu1n5">
   <td><table class="DynamicMenuItemStyle ctl00_Menu1_6" cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
     <td style="white-space:nowrap;width:100%;"><a class="ctl00_Menu1_1 DynamicMenuItemStyle ctl00_Menu1_5" href="/Reviews/All.aspx" style="border-style:none;font-size:1em;">All Reviews</a></td>
    </tr>
   </table></td>
  </tr>
 </table><div class="DynamicMenuItemStyle ctl00_Menu1_6 ctl00_Menu1_0" id="ctl00_Menu1n1ItemsUp" onmouseover="PopOut_Up(this)" onmouseout="PopOut_Stop(this)" style="text-align:center;">
  <img src="/WebResource.axd?d=1aKJpdMaFdnLeyFtf0lA-Eq8_IvFKTXdHuIbdnIa6nI1&amp;t=633735657308550173" alt="Scroll up" />
 </div><div class="DynamicMenuItemStyle ctl00_Menu1_6 ctl00_Menu1_0" id="ctl00_Menu1n1ItemsDn" onmouseover="PopOut_Down(this)" onmouseout="PopOut_Stop(this)" style="text-align:center;">
  <img src="/WebResource.axd?d=ErbaIoEYw2Oj4J569153HnDujPKAMsiB0k9VQxF5YP81&amp;t=633735657308550173" alt="Scroll down" />
 </div>
</div><div id="ctl00_Menu1n2Items" class="ctl00_Menu1_0">
 <table border="0" cellpadding="0" cellspacing="0">
  <tr onmouseover="Menu_HoverDynamic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="Contact Us" id="ctl00_Menu1n6">
   <td><table class="DynamicMenuItemStyle ctl00_Menu1_6" cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
     <td style="white-space:nowrap;width:100%;"><a class="ctl00_Menu1_1 DynamicMenuItemStyle ctl00_Menu1_5" href="/About/Contact.aspx" style="border-style:none;font-size:1em;">Contact Us</a></td>
    </tr>
   </table></td>
  </tr><tr onmouseover="Menu_HoverDynamic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)" title="About Us" id="ctl00_Menu1n7">
   <td><table class="DynamicMenuItemStyle ctl00_Menu1_6" cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
     <td style="white-space:nowrap;width:100%;"><a class="ctl00_Menu1_1 DynamicMenuItemStyle ctl00_Menu1_5" href="/About/AboutUs.aspx" style="border-style:none;font-size:1em;">About Us</a></td>
    </tr>
   </table></td>
  </tr>
 </table><div class="DynamicMenuItemStyle ctl00_Menu1_6 ctl00_Menu1_0" id="ctl00_Menu1n2ItemsUp" onmouseover="PopOut_Up(this)" onmouseout="PopOut_Stop(this)" style="text-align:center;">
  <img src="/WebResource.axd?d=1aKJpdMaFdnLeyFtf0lA-Eq8_IvFKTXdHuIbdnIa6nI1&amp;t=633735657308550173" alt="Scroll up" />
 </div><div class="DynamicMenuItemStyle ctl00_Menu1_6 ctl00_Menu1_0" id="ctl00_Menu1n2ItemsDn" onmouseover="PopOut_Down(this)" onmouseout="PopOut_Stop(this)" style="text-align:center;">
  <img src="/WebResource.axd?d=ErbaIoEYw2Oj4J569153HnDujPKAMsiB0k9VQxF5YP81&amp;t=633735657308550173" alt="Scroll down" />
 </div>
</div><a id="ctl00_Menu1_SkipLink"></a>
 
 
      <br />
    </div>
    <div id="MainContent">
      <span id="ctl00_SiteMapPath1"><a href="#ctl00_SiteMapPath1_SkipLink"><img alt="Skip Navigation Links" height="0" width="0" src="/WebResource.axd?d=JitecEm4xhVPKBoriBdZiw2&amp;t=633735657308550173" style="border-width:0px;" /></a><span><a title="Home" href="/">Home</a></span><span> &gt; </span><span><a title="About this Site" href="/About/Default.aspx">About</a></span><span> &gt; </span><span>Contact Us</span><a id="ctl00_SiteMapPath1_SkipLink"></a></span>
      <br />
    <div>
 
<script type="text/javascript">
  function ValidatePhoneNumbers(source, args) {
    var txtPhoneHome = document.getElementById('ctl00_cpMainContent_ContactForm1_txtPhoneHome');
    var txtPhoneBusiness = document.getElementById('ctl00_cpMainContent_ContactForm1_txtPhoneBusiness');
    if (txtPhoneHome.value != ' ' || txtPhoneBusiness != ' ') 
    {
      args.IsValid = true;
    }
    else 
    {
      args.IsValid = false;
    }
  }
</script>
<table id="ctl00_cpMainContent_ContactForm1_FormTable">
 <tr>
  <td colspan="3">
      Please fill in this form to get in touch with us.</td>
 </tr>
 <tr>
  <td>
      Your name</td>
  <td>
      <input name="ctl00$cpMainContent$ContactForm1$txtName" type="text" id="ctl00_cpMainContent_ContactForm1_txtName" style="width:217px;" />
    </td>
  <td>
      <span id="ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1" style="color:Red;display:none;">*</span>
    </td>
 </tr>
 <tr>
  <td>
      Email address</td>
  <td>
      <input name="ctl00$cpMainContent$ContactForm1$txtEmailAddress" type="text" id="ctl00_cpMainContent_ContactForm1_txtEmailAddress" style="width:266px;" />
    </td>
  <td>
      <span id="ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2" style="color:Red;display:none;">*</span>
      <span id="ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1" style="color:Red;display:none;">*</span>
    </td>
 </tr>
 <tr>
  <td>
      Confirm email address</td>
  <td>
      <input name="ctl00$cpMainContent$ContactForm1$txtEmailAddressConfirm" type="text" id="ctl00_cpMainContent_ContactForm1_txtEmailAddressConfirm" style="width:269px;" />
    </td>
  <td>
      <span id="ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4" style="color:Red;display:none;">*</span>
      <span id="ctl00_cpMainContent_ContactForm1_CompareValidator1" style="color:Red;display:none;">*</span>
    </td>
 </tr>
 <tr>
  <td>
      Home Phone</td>
  <td>
      <input name="ctl00$cpMainContent$ContactForm1$txtPhoneHome" type="text" id="ctl00_cpMainContent_ContactForm1_txtPhoneHome" />
    </td>
  <td>
      <span id="ctl00_cpMainContent_ContactForm1_CustomValidator1" style="color:Red;display:none;">*</span>
    </td>
 </tr>
 <tr>
  <td>
      Business Phone</td>
  <td>
      <input name="ctl00$cpMainContent$ContactForm1$txtPhoneBusiness" type="text" id="ctl00_cpMainContent_ContactForm1_txtPhoneBusiness" />
    </td>
  <td>
      &nbsp;</td>
 </tr>
 <tr>
  <td>
      Comments</td>
  <td>
      <textarea name="ctl00$cpMainContent$ContactForm1$txtComments" rows="2" cols="20" id="ctl00_cpMainContent_ContactForm1_txtComments" style="height:62px;width:273px;"></textarea>
    </td>
  <td>
      <span id="ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3" style="color:Red;display:none;">*</span>
    </td>
 </tr>
 <tr>
  <td>
      &nbsp;</td>
  <td>
      <input type="submit" name="ctl00$cpMainContent$ContactForm1$btnSend" value="Send" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$cpMainContent$ContactForm1$btnSend&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_cpMainContent_ContactForm1_btnSend" class="MyButton" style="background-color:#CCCCCC;" />
    </td>
  <td>
      &nbsp;</td>
 </tr>
 <tr>
  <td colspan="3">
      <div id="ctl00_cpMainContent_ContactForm1_ValidationSummary1" style="color:Red;display:none;">
  </div>
    </td>
 </tr>
</table>
 
<p>
  &nbsp;</p>
 
</div>
    </div>
    <div id="Sidebar">
      Select a Theme
      <select name="ctl00$lstPreferredTheme" onchange="javascript:setTimeout('__doPostBack(\'ctl00$lstPreferredTheme\',\'\')', 0)" id="ctl00_lstPreferredTheme">
 <option selected="selected" value="Monochrome">Monochrome</option>
 <option value="DarkGrey">DarkGrey</option>
</select>
      <br />
      <br />
      <br />
      <div id="ctl00_Banner1_pnlVertical">
 
  <a href="http://p2p.wrox.com" id="ctl00_Banner1_lnkVertical" target="_blank"><img id="ctl00_Banner1_Image1" src="../Images/Banner120x240.gif" alt="This is a sample banner" style="border-width:0px;" />
    </a>
</div>
 
    </div>
    <div id="Footer">Footer Goes Here</div>
  </div>
 
<script type="text/javascript">
//<![CDATA[
var Page_ValidationSummaries =  new Array(document.getElementById("ctl00_cpMainContent_ContactForm1_ValidationSummary1"));
var Page_Validators =  new Array(document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1"), document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2"), document.getElementById("ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1"), document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4"), document.getElementById("ctl00_cpMainContent_ContactForm1_CompareValidator1"), document.getElementById("ctl00_cpMainContent_ContactForm1_CustomValidator1"), document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1"] : document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1");
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtName";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1.errormessage = "Please enter your name";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator1.initialvalue = "";
var ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2"] : document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2");
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtEmailAddress";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2.errormessage = "Please enter an email address";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator2.initialvalue = "";
var ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1"] : document.getElementById("ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1");
ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtEmailAddress";
ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1.errormessage = "Please enter a valid email address";
ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_RegularExpressionValidator1.validationexpression = "\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
var ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4"] : document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4");
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtEmailAddressConfirm";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4.errormessage = "Please confirm the email address";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator4.initialvalue = "";
var ctl00_cpMainContent_ContactForm1_CompareValidator1 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_CompareValidator1"] : document.getElementById("ctl00_cpMainContent_ContactForm1_CompareValidator1");
ctl00_cpMainContent_ContactForm1_CompareValidator1.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtEmailAddressConfirm";
ctl00_cpMainContent_ContactForm1_CompareValidator1.errormessage = "Please retype the email address";
ctl00_cpMainContent_ContactForm1_CompareValidator1.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_CompareValidator1.evaluationfunction = "CompareValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_CompareValidator1.controltocompare = "ctl00_cpMainContent_ContactForm1_txtEmailAddress";
ctl00_cpMainContent_ContactForm1_CompareValidator1.controlhookup = "ctl00_cpMainContent_ContactForm1_txtEmailAddress";
var ctl00_cpMainContent_ContactForm1_CustomValidator1 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_CustomValidator1"] : document.getElementById("ctl00_cpMainContent_ContactForm1_CustomValidator1");
ctl00_cpMainContent_ContactForm1_CustomValidator1.errormessage = "Please enter home or business phone number";
ctl00_cpMainContent_ContactForm1_CustomValidator1.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_CustomValidator1.evaluationfunction = "CustomValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_CustomValidator1.clientvalidationfunction = "ValidatePhoneNumbers";
var ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3 = document.all ? document.all["ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3"] : document.getElementById("ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3");
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3.controltovalidate = "ctl00_cpMainContent_ContactForm1_txtComments";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3.errormessage = "Please enter a comment";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3.display = "Dynamic";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_cpMainContent_ContactForm1_RequiredFieldValidator3.initialvalue = "";
//]]>
</script>
 
<script type="text/javascript">
//<![CDATA[
var ctl00_Menu1_Data = new Object();
ctl00_Menu1_Data.disappearAfter = 500;
ctl00_Menu1_Data.horizontalOffset = 0;
ctl00_Menu1_Data.verticalOffset = 0;
ctl00_Menu1_Data.hoverClass = 'ctl00_Menu1_12 DynamicHoverStyle';
ctl00_Menu1_Data.hoverHyperLinkClass = 'ctl00_Menu1_11 DynamicHoverStyle';
ctl00_Menu1_Data.staticHoverClass = 'ctl00_Menu1_10 StaticHoverStyle';
ctl00_Menu1_Data.staticHoverHyperLinkClass = 'ctl00_Menu1_9 StaticHoverStyle';
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
    ValidatorOnLoad();
}
function ValidatorOnSubmit() {
    if (Page_ValidationActive) {
        return ValidatorCommonOnSubmit();
    }
    else {
        return true;
    }
}
        //]]>
</script>
</form>
</body>
</html>
Reply With Quote
  #4 (permalink)  
Old May 13th, 2009, 03:07 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi nkem,

You have two errors in your client validation function. First, you're comparing with a space, not an empty string. E.g. you need to use '' instead of ' '.

Secondly, you're not requesting the value of the txtPhoneBusiness text box, but you're comparing the entire control. That is, txtPhoneBusiness != '' is never true, as the entire control is never an empty space. Using txtPhoneBusiness.value != '' should do the trick.

So to summarize: you have this:

Code:
if (txtPhoneHome.value != ' ' || txtPhoneBusiness != ' ')
but it should be:

Code:
 
if (txtPhoneHome.value != '' || txtPhoneBusiness.value != '')
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!
Reply With Quote
  #5 (permalink)  
Old May 14th, 2009, 11:14 AM
Registered User
 
Join Date: May 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Imar, I wasn't able to respond as I was away from computers yesterday. I noticed and corrected the empty string quotes already, but didn't catch the missing ".value" after the business phone variable in the javascript.
Thank you so much. I really appreciate you looking at my code!
Nkem
Reply With Quote
  #6 (permalink)  
Old May 14th, 2009, 11:37 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome....

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!
Reply With Quote
  #7 (permalink)  
Old January 21st, 2012, 07:56 PM
Authorized User
Points: 393, Level: 6
Points: 393, Level: 6 Points: 393, Level: 6 Points: 393, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default Chapter 9 Custom Validator

Dear Imar,

I do have the same problem as nkem that is I cannot see the asterisk nor the message but my code I beleive it is correct. Please help.
Markup
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ContactForm.ascx.vb" Inherits="Controls_ContactForm" %>

<% If False Then%>
<script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<% End If%>

<style type="text/css">
  .style1
  {
    width: 100%;
  }
  .style2
  {
    width: 127px;
  }
  .style3
  {
  }
  .style4
  {
    width: 151px;
    height: 23px;
  }
  .style5
  {
    width: 127px;
    height: 23px;
  }
  .style6
  {
    height: 23px;
  }
  .style7
  {
    height: 79px;
  }
  .style8
  {
    width: 127px;
    height: 79px;
  }
  </style>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
  <script type="text/javascript">
    function ValidatePhoneNumbers(source, args)
    {
      var phoneHome = document.getElementById('PhoneHome');
      var phoneBusiness = document.getElementById('PhoneBusiness');
      if (phoneHome.value != '' || phoneBusiness.value != '')
      {
        args.isvalid = true;
      }
      else
      {
        args.isvalid = false;
      }
    }

  </script>

 
  <table class="style1" runat="server" id="FormTable">
  <tr>
    <td colspan="2">
      <h2>Get in touch with us</h2>
      <h3>Please use this form to get in touch with us. Enter your name,
      <br />e-mail address, and your home or business phone number.</h3></td>
      
  </tr>
  <tr>
    <td class="style3">
      Name</td>
    <td class="style2">
      <asp:TextBox ID="Name" runat="server" Width="320px"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="Name" CssClass="ErrorMessage" 
        ErrorMessage="Enter your name" Display="Dynamic">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="style3">
      E-mail address</td>
    <td class="style2">
      <asp:TextBox ID="EmailAddress" runat="server" Width="320px"></asp:TextBox>
    </td>
    <td style="margin-left: 40px">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
        CssClass="ErrorMessage" 
        ErrorMessage="Enter an e-mail address" ControlToValidate="EmailAddress" 
        Display="Dynamic">*</asp:RequiredFieldValidator>
      <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="EmailAddress" 
        CssClass="ErrorMessage" 
        ErrorMessage="Enter a valid e-mail address" 
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
        Display="Dynamic"></asp:RegularExpressionValidator>
    </td>
  </tr>
  <tr>
    <td class="style3">
      Confirm E-mail address</td>
    <td class="style2">
      <asp:TextBox ID="ConfirmEmailAddress" runat="server" Width="320px"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
        CssClass="ErrorMessage" 
        ErrorMessage="Confirm the e-mail address" 
        ControlToValidate="ConfirmEmailAddress" Display="Dynamic">*</asp:RequiredFieldValidator>
      <asp:CompareValidator ID="CompareValidator1" runat="server" 
        ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" 
        CssClass="ErrorMessage" 
        ErrorMessage="Retype the e-mail address" Display="Dynamic"></asp:CompareValidator>
    </td>
  </tr>
  <tr>
    <td class="style3">
      Home phone number</td>
    <td class="style2">
      <asp:TextBox ID="PhoneHome" runat="server" Width="321px" ClientIDMode="Static"></asp:TextBox>
    </td>
    <td>
      <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Enter your home or business phone number"
        ClientValidationFunction="ValidatePhoneNumbers" OnServerValidate="CustomValidator1_serverValidate"
        Display="Dynamic" CssClass="ErrorMessage">*</asp:CustomValidator>
    </td>
  </tr>
  <tr>
    <td class="style4">
      Business phone number</td>
    <td class="style5">
      <asp:TextBox ID="PhoneBusiness" runat="server" Width="320px" 
        ClientIDMode="Static"></asp:TextBox>
    </td>
    <td class="style6">
      </td>
  </tr>
  <tr>
    <td class="style7">
      Comments</td>
    <td class="style8">
      <asp:TextBox ID="Comments" runat="server" TextMode="MultiLine" Width="320px" 
        Height="69px"></asp:TextBox>
    </td>
    <td class="style7">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
        ControlToValidate="Comments" CssClass="ErrorMessage" 
        ErrorMessage="Enter a comment" Display="Dynamic">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="style3">
      &nbsp;</td>
    <td class="style2">
      <asp:Button ID="SendButton" runat="server" Text="Send" />
    </td>
    <td>
      &nbsp;</td>
  </tr>
  <tr>
    <td class="style3" colspan="3">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
        CssClass="ErrorMessage" 
        
        HeaderText="Please correct the following errors before you press the Send button" 
        ShowMessageBox="True" ShowSummary="False" />
    </td>
  </tr>
</table>

  <asp:Label ID="Message" runat="server" CssClass="Attention" Text="Message Sent" Visible="False" 
    style="text-align: center; color: #FF3300" />

 <p runat ="server" id="MessageSentPara" visible="false" 
    style="color: #FFFF00">Thank you for your message.<br /> We'll get in touch with you if necessary.</p>


  </ContentTemplate>
</asp:UpdatePanel>


<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="PleaseWait">
  Please Wait...
</div>
</ProgressTemplate>
</asp:UpdateProgress>


<script type="text/javascript">



  function pageLoad()
  {
   
     $('.Attention').animate({ width: '600px' }, 3000).animate({ width: '100px' }, 3000).fadeOut('slow');
  }
</script>
VB
Code:
Protected Sub CustomValidator1_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.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
Thanks
Khalil

Last edited by Khalil; January 22nd, 2012 at 12:26 AM..
Reply With Quote
  #8 (permalink)  
Old January 22nd, 2012, 05:40 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Take a look at this:

Code:
 
args.isvalid = true;
IsValid should have two capitals. E.g.:

Code:
 
args.IsValid = true;
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!
Reply With Quote
  #9 (permalink)  
Old January 23rd, 2012, 06:33 AM
Authorized User
Points: 393, Level: 6
Points: 393, Level: 6 Points: 393, Level: 6 Points: 393, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default Chapter 11 Animation

Hi Imar,

Thank you for your reply to my last query in which you corrected my code. My problem has been resolved. I now have one last query and would appreciate your continuous support.

In page 393, there is a code to animate "message sent". I also wish to animate the "MessageSentPara" after the "message sent" disappears, and tried different ways but nothing seems to work.

First, I went to VB and removed "MessageSentPara.visible = True" then I added a line of code to the exisiting one.
Code:
function pageLoad()
  {
    $('.Attention').animate({ width: '600px' }, 3000).animate({ width: '100px' }, 3000).fadeOut('slow');
    $('.MessageSentPara').show().fadeOut('slow');
  }
Thanks and regards
Reply With Quote
  #10 (permalink)  
Old January 23rd, 2012, 10:11 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi therem

Quote:
First, I went to VB and removed "MessageSentPara.visible = True"
When you do that, the text is hidden at the server and never makes it to the client.

Quote:
$('.MessageSentPara').show().fadeOut('slow');
Does the text have a CSS class of MessageSentPara? If not, this selector is never going to match. Either add a CSS class to it, or use an ID selector (e.g. something like

'#' + <%=MessageSentPara.ClientID%>'

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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Khalil (January 24th, 2012)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Validator against a database Steve Spicer ASP.NET 2.0 Professional 16 January 12th, 2008 06:25 AM
trying to make a custom label for phone numbers... thenoseknows ASP.NET 2.0 Professional 2 August 22nd, 2006 06:07 PM
dinamically showing a .swf file in a popup window ACE2084 ASP.NET 1.0 and 1.1 Basics 7 April 27th, 2005 10:59 AM
showing a popup window on click widad Classic ASP Basics 4 October 15th, 2004 09:50 AM
Custom Validator bmains ASP.NET 1.0 and 1.1 Basics 4 December 18th, 2003 11:45 AM



All times are GMT -4. The time now is 07:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.