Wrox Programmer Forums
|
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 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 December 22nd, 2009, 06:57 AM
Authorized User
 
Join Date: Dec 2009
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,
I am on page 304, and do not get the desired behavior, when i request contact.aspx in browser. I have changed properties of ValidationSummery control like this.

ShowMessageBox to True and ShowSummery to False. Also i set the HeaderText property to:Please correct the following errors before you press the Send button.

When i leave out phone number textboxes in browser, and then press the send button i should be getting messagebox with list of errors preceded with the HeaderText of the validationSummery.

But, i don't get any Alert box.

here is the server side code

Code:
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;
      }
    }
}
and here is the client side code

Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>

<script runat="server">

</script>



<style type="text/css">
  .style1
  {
    width: 100%;
  }
  .style2
  {
    font-size: large;
    font-weight: bold;
  }
</style>
<script type="text/javascript">
  function ValidatePhoneNumbers(source, args) 
  {
    var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
    var txtPhoneBusiness = document.getElementById('<%=txtPhoneBusiness.ClientID %>');
    if (txtPhoneHome.value != ' ' || txtPhoneBusiness.value != ' ') 
    {
      args.IsValid = true;
    }
    else 
    {
      args.IsValid = false;
    }


  }
</script>
<table class="style1">
  <tr>
    <td colspan="3">
      <span class="style2">Get in touch with us</span><br />
      <br />
      Use the form below to get in touch with us. Enter your name, e-mail address and 
      your home or phone number to get in touch with us.</td>
  </tr>
  <tr>
    <td>
      Your name:</td>
    <td>
      <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ErrorMessage="Please enter your name" ControlToValidate="txtName">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td>
      Your e-mail address:</td>
    <td>
      <asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
        ControlToValidate="txtEmailAddress" Display="Dynamic" 
        ErrorMessage="Please enter an e-mail address">*</asp:RequiredFieldValidator>
      <br />
      <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="txtEmailAddress" Display="Dynamic" 
        ErrorMessage="Please enter a valid e-mail address" 
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
    </td>
  </tr>
  <tr>
    <td>
      Your e-mail address again:</td>
    <td>
      <asp:TextBox ID="txtEmailaddressConfirm" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
        ControlToValidate="txtEmailaddressConfirm" Display="Dynamic" 
        ErrorMessage="Please confirm the email address">*</asp:RequiredFieldValidator>
      <br />
      <asp:CompareValidator ID="CompareValidator1" runat="server" 
        ControlToCompare="txtEmailAddress" ControlToValidate="txtEmailaddressConfirm" 
        Display="Dynamic" ErrorMessage="Please retype the e-mail address">*</asp:CompareValidator>
    </td>
  </tr>
  <tr>
    <td>
      Home phone number:</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 your home or business phone number" 
        onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
    </td>
  </tr>
  <tr>
    <td>
      Business phone number:</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="89px" 
        style="margin-bottom: 0px" TextMode="MultiLine" Width="470px"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
        ControlToValidate="txtComments" Display="Dynamic" 
        ErrorMessage="Please enter comment">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td>
      &nbsp;</td>
    <td>
      <asp:Button ID="btnSend" runat="server" Text="Send" />
    </td>
    <td>
      &nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
        HeaderText="Please correct the following errors before you press the send button" 
        ShowMessageBox="True" ShowSummary="False" />
    </td>
  </tr>
</table>


I am sure, somewhere i am making mistake,

thanx in advance for any help

Arya

Last edited by Arya; December 22nd, 2009 at 07:12 AM..
 
Old December 22nd, 2009, 07:23 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 Arya,

Can it be this:

Code:
if (txtPhoneHome.value != ' ' || txtPhoneBusiness.value != ' ')
There's a space between the single quotes, so when the fields don't equal a space (which is true for an empty value) do you consider them valid...

HtH,

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 December 22nd, 2009, 11:17 AM
Authorized User
 
Join Date: Dec 2009
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

oh!,ok...
I corrected it, and it works! what a silly mistake i did!

thanx Imar,

Arya





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 Page 95 jumpot89 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 6 April 22nd, 2009 03:11 AM
Chapter 9, page 304 Again AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 June 15th, 2008 02:57 PM
Chapter 9 JavaScript Warning Message Page 304 workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 May 28th, 2008 04:42 PM
Chapter 7 page 212 tgregory BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 May 3rd, 2007 01:44 PM
Chapter 7 Try It Out page 218 drumdiva BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 3 March 19th, 2007 08:35 PM





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