Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 December 20th, 2011, 12:09 AM
Authorized User
 
Join Date: Dec 2011
Posts: 26
Thanks: 1
Thanked 4 Times in 3 Posts
Default 1st Watermark Putting All Together exercise not working

Hello,
I am working through your example on pg. 335 where you first introduce the watermark. It is not working for me at all. I do not see the grey text in the fields.

I tried comparing the code in the ContactForm.ascx file that I downloaded from the site, but the code in the script block in that file is not similar at all to what is in this exercise.

I have tried adding the following (which were in the downloaded source), but that was to no avail.
Code:
<% if (false)
   { %>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<% } %>
<script src="../Scripts/jquery.updnWatermark.js" type="text/javascript"></script>
This is my complete ContactForm.aspx file as I believe it should be after following that exercise (and having followed the exercises before it).

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

<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>

<style type="text/css">
  .Watermark
  {
      font-style: italic;
      color: Gray;
  }
  
  .style1
  {
    width: 100%;
  }
</style>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="style1" runat="server" id="FormTable">
    <tr>
        <td colspan="3" style="text-align: center">
            Contact Us using this form</td>
    </tr>
    <tr>
        <td>
            Name</td>
        <td>
            <asp:TextBox ID="Name" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="Name" CssClass="ErrorMessage" ErrorMessage="Enter your name">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            Email Address</td>
        <td>
            <asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter an email address">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="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="ConfirmEmailAddress" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Confirm the email address">*</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" 
                CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Retype the email address">*</asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td>
            Home Phone Number</td>
        <td>
            <asp:TextBox ID="PhoneHome" runat="server" ClientIDMode="Static"></asp:TextBox>
        </td>
        <td>
            <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>
        </td>
    </tr>
    <tr>
        <td>
            Business Phone Number</td>
        <td>
            <asp:TextBox ID="PhoneBusiness" runat="server" ClientIDMode="Static"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            Comments</td>
        <td>
            <asp:TextBox ID="Comments" runat="server" TextMode="MultiLine"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                ControlToValidate="Comments" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter a comment">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            <asp:Button ID="SendButton" runat="server" Text="Send" 
                onclick="SendButton_Click" />
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td colspan="3">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                CssClass="ErrorMessage" 
                HeaderText="Please correct the following errors before you press the Send button:" 
                ShowMessageBox="False" ShowSummary="True" />
        </td>
    </tr>
</table>


<asp:Label ID="Message" runat="server" Text="Message Sent" Visible="False"></asp:Label>

</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()
 {
    $(':input[type=text], textarea').each
    (
        function()
        {
            var newText = "Please enter your " + 
                $(this).parent().prev().text.toLowerCase().trim();
            $(this).attr('value', newText);
     }).one('focus',function()
            {
                this.value= ", this.className = "
             }).addClass('Watermark').css('width','300px');
  });
 </script>
Thanks for any help.
 
Old December 20th, 2011, 05:38 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,

Take a look at this:

Code:
 
$(this).parent().prev().text.toLowerCase().trim();
text is a method and thus needs parentheses:

Code:
 
$(this).parent().prev().text().toLowerCase().trim();
Does that fix the issue?

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 20th, 2011, 10:03 PM
Authorized User
 
Join Date: Dec 2011
Posts: 26
Thanks: 1
Thanked 4 Times in 3 Posts
Default yeap. fixed.

yeap, that fixes it. Figures that it would be a typo. I guess I thought that was what it was, but I checked over the code multiple times and just missed that everytime. Must be my SQL training or something... anyway, thanks.
 
Old December 21st, 2011, 09:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In case it makes you feel better: I used a tool. Couldn't see what was wrong either, so I used a diff tool to compare your code and mine.... ;-)

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 December 22nd, 2011, 11:28 AM
Authorized User
 
Join Date: Dec 2011
Posts: 26
Thanks: 1
Thanked 4 Times in 3 Posts
Default what tool?

what tool do you use for that compare?
 
Old December 23rd, 2011, 03:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In my case I used a Diff tool from Source Gear which came as part of a source control system. You can also look at tools such as WinDiff and Beyond Compare.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Watermark not working floridaguy BOOK: Professional ASP.NET 4 : in C# and VB 2 August 15th, 2011 10:19 AM
Chapter 2 - 1st exercise gomesdir BOOK: Beginning JavaServer Pages 4 April 6th, 2006 08:13 PM





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