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>
</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>
</td>
<td>
<asp:Button ID="SendButton" runat="server" Text="Send"
onclick="SendButton_Click" />
</td>
<td>
</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.