 |
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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
|
|
|
|
|

February 18th, 2016, 09:42 AM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 9 - Validating User Controls (P.317)
Hi,
If you navigate to the page/try it out exercise on page 317, I am stuck on the last steps:
8. Go back to VS and click the ValidationSummary control in Design View. On the Properties Grid,
change ShowMessageBox to True and ShowSummary to
False. (Quick tip: you can easily choose the next item
in a drop-down list on the Properties Grid by
double-clicking the value. For booleans, this means that
if you double-click False, it turns to True and vice versa).
Also, set its HeaderText property to Please correct the
following errors:.
9. Open the page in the browser again and click the Send
button once more. Note that instead of the inline list with
errors, you now get a client-side alert, shown in Figure 9-9.
The list of errors is preceded with the HeaderText of the
ValidationSummary.
I have set the properties as specified:
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors:" ShowMessageBox="True" ShowSummary="False" />
However the pop up dialogue isn't appearing when I select the send button.
Additional:
So before that step, I previewed the page on chrome and the summary worked (appearing as bulletted list). Its only when I change the properties on the final step that the list doesn't appear, neither in bullet list format OR in the dialogue box (the latter being the expected result)
Is there something I have looked over on this? Please let me know
PS: Great book, I am able to follow the process you have set out easily. This is the first issue I have encountered. Let me know :)
Thanks
Qas
|
|

February 21st, 2016, 09:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
A few things to check:
1. Are there any script errors? Try looking at the Developer tools in your browser and see if you can find anything.
2. Post the full code for the control and the page that uses it. There might be something else preventing the popup.
3. Look at the full, final HTML for the page (and post it here). Maybe there is broken JavaScript somewhere preventing your code to run successfully.
Cheers,
Imar
|
|

February 22nd, 2016, 06:42 AM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
1. Couldn't find anything too obvious apart from the below. Not sure if it could be related to the issue:
Code:
WebSocket connection to 'ws://localhost:51163/31f867167659470d934491b9b487d82b/arterySignalR/connect?transport=webSockets&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAbkio%2B%2BuliEmReL2W3wRUbQAAAAACAAAAAAADZgAAwAAAABAAAADL6kev1K59WWMIRaZb%2BOi2AAAAAASAAACgAAAAEAAAALjQ8uSLnzaPygJ3xcaUALIoAAAA%2FjGrkITf3cFL2eIiUyIzwM2uQ6Lp49tBWwDxwbNwUOij5kNo4yNYvRQAAABzeCt9%2F6jvn9sB2WkxW4UDRn6toQ%3D%3D&requestUrl=http%3A%2F%2Flocalhost%3A65104%2FAbout%2FContact&browserName=Chrome&userAgent=Mozilla%2F5.0+(Windows+NT+6.3%3B+WOW64)+AppleWebKit%2F537.36+(KHTML%2C+like+Gecko)+Chrome%2F48.0.2564.109+Safari%2F537.36&tid=4' failed: WebSocket is closed before the connection is established.
2.
ContactForm.ascx:
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 315px;
}
</style>
<script>
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>
<table class="auto-style1">
<tr>
<td colspan="3">Use the form below to get in touch with us/ Enter your name, e-mail address, and your home or business phone number to get in touch with us.</td>
</tr>
<tr>
<td>Name</td>
<td class="auto-style2">
<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>E-mail address</td>
<td class="auto-style2">
<asp:TextBox ID="EmailAddress" runat="server" TextMode="Email"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Enter an e-mail address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Enter a valid e-mail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>Repeat e-mail address</td>
<td class="auto-style2">
<asp:TextBox ID="ConfirmEmailAddress" runat="server" TextMode="Email"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Confirm the e-mail">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="The e-mail addresses">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td>Home phone number</td>
<td class="auto-style2">
<asp:TextBox ID="PhoneHome" runat="server"></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 class="auto-style2">
<asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td>Comments</td>
<td class="auto-style2">
<asp:TextBox ID="Comments" runat="server" Height="120px" TextMode="MultiLine" Width="220px"></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 class="auto-style2">
<asp:Button ID="SendButton" runat="server" Text="Send" />
</td>
<td> </td>
</tr>
<tr>
<td colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors:" ShowMessageBox="True" ShowSummary="False" />
</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;
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 (!string.IsNullOrEmpty (PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}
Contact Us page (page which uses the control):
Code:
<%@ Page Title="Contact Us" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="Contact.aspx.cs" Inherits="About_Contact" %>
<%@ Register Src="~/Controls/ContactForm.ascx" TagPrefix="Wrox" TagName="ContactForm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<h1>Contact Us</h1>
<Wrox:ContactForm runat="server" ID="ContactForm" />
</asp:Content>
3.
Final HTML of page:
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Contact Us
</title>
<script src="/Scripts/modernizr-2.7.1.js"></script>
<link href="../App_Themes/Monochrome/Monochrome.css" type="text/css" rel="stylesheet" /><style type="text/css">
/* <![CDATA[ */
#Menu1 img.icon { border-style:none;vertical-align:middle; }
#Menu1 img.separator { border-style:none;display:block; }
#Menu1 img.horizontal-separator { border-style:none;vertical-align:middle; }
#Menu1 ul { list-style:none;margin:0;padding:0;width:auto; }
#Menu1 ul.dynamic { z-index:1; }
#Menu1 a { text-decoration:none;white-space:nowrap;display:block; }
#Menu1 a.static { padding-left:0.15em;padding-right:0.15em; }
#Menu1 a.popout-dynamic { background:url("/WebResource.axd?d=YAYach_zykzn7tRotFpEUn5_6Gk4X5xROSg0mBo_6lLVUqoNpGrl7senjIFiEFRcxqCbtGkejAylgpom7wkR-FL4xFWBqDHJ2ixlg8vmh9w1&t=635793063765829480") no-repeat right center;padding-right:14px; }
/* ]]> */
</style></head>
<body>
<form method="post" action="./Contact" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div class="aspNetHidden">
<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="55F54VQistnrp6k1yv1Lmh44+u8SpQoRMA20rR9zTC6b9Fm9STXAMoWzHlD4mDdXN41DOQSuGsxjlzPWX6qzrYjav+vFZRqUcaiT2iA80uynIVRwGnctolgwqQPwrrr6/eTI7JBsTxiqoJBNAqdBTp0MV+5ch1G3A4xjY7+F70d3ennvZHApD5WH3SVUMSB6cQX1kQSrTmSL8XQecZwYnFkBU9WmTXFtCqDaEdynpsPU4FRfCbjkjjAyqkYz4uvJi0tBVFfsXoKkGoMam3hHUDkwWxZXKBU4DtmKj9poYo8QAaQ6TRSXdaSy2zzuGYHRjrgyLmnIA6EhsEqZKFTv301vKEKBY65/JQFRsjGYA6NrhN/+5ZyqqnSwymvKo6WVm+SwKZBcvckaXtZ/cTlgVOeEmD3UraT0xAAM+qUHUqZK3vmfE6JiAH3M4+oT1qJZGJPp5uSRlmFC3hfOI9iaWrYs3xxR0mXC1xE8ui6XhcyErJfFqkkENRPk67asnp6YNZeVtWvsclQIdO2DIp9q/MJur0x3n4jADAH2ex90VmZx0M6B7bBxI62VRn2qzM2qRO0dTkqNGjL6N6CKhrKKoHHhMow1skz0SiTUeFiQRvsDUGO3KOGKvDNDqzq4+oFsd5kHszCMxTaKM9FTmTdgF0l0AEdd06/vQjJD8HqQMlCdm925ZYYFFs7WpL4PAFsRtFvBGi6L9R3dhiSDDjm/3hX+OEUWuX+RvCGTIGfhsLpmqR7HcDv8pdssWiZ/zo4LQYDwcJzpgbHXF+8WFbVEf5RKZWms9q6t7IVVr80/jiFNpXYlPt+cVXeAPEbGpmA4dY3UCBM1Ilp8i3obPuGxDPb3iGV1khpj1TWe2xGHbzkQwfkawNkHC9hlax+AVEoxE67NHGN68ZfnCvlOYDJUhYmXMF8SA5eP0fd9h4CdsuJPx8XRZgmE4CPNUvleRzHNM0EXWzVpGm5h88MZZxKuzopRCzEPfilSPVtzPKPJk6oYf45leRKFnq/9cR6GmlEkSHHY/YEE+y7BOMas609RjMoox0N+nBnI29ko3CNY1zc2lOFHR28EOqB5/NmBFntPCveQAnAHYsmV0m+l0T5xoYZxLPMOAE2yOGYMkiqhh8nPJEiT3a+mM1xVM1ON6XTHuOGGGaTq3F2YflwpRl25xRCHaYnNHanJgiiY17MDctQLYN7NARYGS3u9+n42fepkRaaD/A33LB91SGCO1RWSCN6LBsWmLoxCtFqH9HQpAEnKxHKwKIcaxsdQYnKzYdCXwhxyRa8vT9LtU1HnNT/FxnWtiNh+WntgYJMAFBuvHrf5hmni6ABJM0wHmE5LEa2OnBUOuZes8Mo5JkYDpM+lcSivRcSSOmg7qAK9bxCqZxsR7PUkGKFCoS1docC+KWkWj242CR9GwcvHrWRulzq9l8F7LN+YglZUdGtQLjUB0QPawUOmQiwO6mNymf9mHD15flP5a270TBaj0lHYQSUsc/g0JnonIW56qLdCsJZ0aAM=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
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=pynGkmcFUV13He1Qd6_TZEHMS9vOCf0Uw8V-IgT4CO3uDYCxvtTyfZIUf2CYRZcJNjFnfVc4meUYs36z2pCmAQ2&t=635793063765829480" type="text/javascript"></script>
<script src="/WebResource.axd?d=fqV81KWLWhVg-lLAb4IT63F42xDoIYD25V-UOf9k4ENvAfN44MdIwge_oXNGhpizER1JJDBMLh8JghqgzAkQ1k8gnbIpgxK0IJtgb6YSyHw1&t=635793063765829480" type="text/javascript"></script>
<script src="/WebResource.axd?d=x2nkrMJGXkMELz33nwnakM44OkeQQmmJqPGILmxxarNBp8U-zEwuTlf2x-V376W6f9h2VoCX-rjHFRGV-xI0Z779vAEYDWlY3d3CygJFafg1&t=635793063765829480" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
<div id="PageWrapper">
<header><a href="/"></a></header>
<nav>
<a href="#Menu1_SkipLink" style="position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;">Skip Navigation Links</a><div class="MainMenu" id="Menu1">
<ul class="level1">
<li><a title="Go to the homepage" class="level1" href="/Default">Home</a></li><li><a title="Reviews published on this site" class="level1" href="/Reviews/Default">Reviews</a><ul class="level2">
<li><a title="All Reviews Grouped by Genre" class="level2" href="/Reviews/AllByGenre">By Genre</a></li><li><a title="All Reviews" class="level2" href="/Reviews/All">All Reviews</a></li>
</ul></li><li><a title="About this Site" class="level1" href="/About/Default">About</a><ul class="level2">
<li><a title="Contact Us" class="level2 selected" href="/About/Contact">Contact Us</a></li><li><a title="About Us" class="level2" href="/About/AboutUs">About Us</a></li>
</ul></li><li><a title="Log in to this web site" class="level1" href="/Login">Login</a></li>
</ul>
</div><a id="Menu1_SkipLink"></a>
</nav>
<section id="MainContent">
<span id="SiteMapPath1"><a href="#SiteMapPath1_SkipLink" style="position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;">Skip Navigation Links</a><span><a title="Home" href="/">Home</a></span><span> > </span><span><a title="About this Site" href="/About/Default">About</a></span><span> > </span><span>Contact Us</span><a id="SiteMapPath1_SkipLink"></a></span>
<br />
<br />
<h1>Contact Us</h1>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 315px;
}
</style>
<script>
function validatePhoneNumbers(source, args)
{
var phoneHome = document.getElementById('cpMainContent_ContactForm_PhoneHome');
var phoneBusiness = document.getElementById('cpMainContent_ContactForm_PhoneBusiness ');
if (phoneHome.value != '' || phoneBusiness.value != '')
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
<table class="auto-style1">
<tr>
<td colspan="3">Use the form below to get in touch with us/ Enter your name, e-mail address, and your home or business phone number to get in touch with us.</td>
</tr>
<tr>
<td>Name</td>
<td class="auto-style2">
<input name="ctl00$cpMainContent$ContactForm$Name" type="text" id="cpMainContent_ContactForm_Name" />
</td>
<td>
<span id="cpMainContent_ContactForm_RequiredFieldValidator1" class="ErrorMessage">*</span>
</td>
</tr>
<tr>
<td>E-mail address</td>
<td class="auto-style2">
<input name="ctl00$cpMainContent$ContactForm$EmailAddress" type="email" id="cpMainContent_ContactForm_EmailAddress" />
</td>
<td>
<span id="cpMainContent_ContactForm_RequiredFieldValidator2" class="ErrorMessage">*</span>
<span id="cpMainContent_ContactForm_RegularExpressionValidator1" class="ErrorMessage" style="display:none;">*</span>
</td>
</tr>
<tr>
<td>Repeat e-mail address</td>
<td class="auto-style2">
<input name="ctl00$cpMainContent$ContactForm$ConfirmEmailAddress" type="email" id="cpMainContent_ContactForm_ConfirmEmailAddress" />
</td>
<td>
<span id="cpMainContent_ContactForm_RequiredFieldValidator3" class="ErrorMessage">*</span>
<span id="cpMainContent_ContactForm_CompareValidator1" class="ErrorMessage" style="display:none;">*</span>
</td>
</tr>
<tr>
<td>Home phone number</td>
<td class="auto-style2">
<input name="ctl00$cpMainContent$ContactForm$PhoneHome" type="text" id="cpMainContent_ContactForm_PhoneHome" />
</td>
<td>
<span id="cpMainContent_ContactForm_CustomValidator1" class="ErrorMessage">*</span>
</td>
</tr>
<tr>
<td>Business phone number</td>
<td class="auto-style2">
<input name="ctl00$cpMainContent$ContactForm$PhoneBusiness" type="text" id="cpMainContent_ContactForm_PhoneBusiness" />
</td>
<td> </td>
</tr>
<tr>
<td>Comments</td>
<td class="auto-style2">
<textarea name="ctl00$cpMainContent$ContactForm$Comments" rows="2" cols="20" id="cpMainContent_ContactForm_Comments" style="height:120px;width:220px;">
</textarea>
</td>
<td>
<span id="cpMainContent_ContactForm_RequiredFieldValidator4" class="ErrorMessage">*</span>
</td>
</tr>
<tr>
<td> </td>
<td class="auto-style2">
<input type="submit" name="ctl00$cpMainContent$ContactForm$SendButton" value="Send" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cpMainContent$ContactForm$SendButton", "", true, "", "", false, false))" id="cpMainContent_ContactForm_SendButton" class="MyButton" style="background-color:#509EE7;" />
</td>
<td> </td>
</tr>
<tr>
<td colspan="3">
<div id="cpMainContent_ContactForm_ValidationSummary1" class="ErrorMessage" style="display:none;">
</div>
</td>
</tr>
</table>
</section>
<aside id="Sidebar">
Select a theme
<br />
<select name="ctl00$ThemeList" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ThemeList\',\'\')', 0)" id="ThemeList">
<option selected="selected" value="Monochrome">Monochrome</option>
<option value="DarkGrey">DarkGrey</option>
</select>
<br />
<br />
<div id="Banner1_VerticalPanel">
<a href="http://p2p.wrox.com" id="Banner1_VerticalLink" target="_blank">
<img id="Banner1_Image1" src="../Images/Banner120x240.gif" alt="This is a sample banner" />
</a>
</div>
<br />
</aside>
<footer>Footer Goes Here</footer>
</div>
<script type="text/javascript">
//<![CDATA[
var Page_ValidationSummaries = new Array(document.getElementById("cpMainContent_ContactForm_ValidationSummary1"));
var Page_Validators = new Array(document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator1"), document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator2"), document.getElementById("cpMainContent_ContactForm_RegularExpressionValidator1"), document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator3"), document.getElementById("cpMainContent_ContactForm_CompareValidator1"), document.getElementById("cpMainContent_ContactForm_CustomValidator1"), document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator4"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var cpMainContent_ContactForm_RequiredFieldValidator1 = document.all ? document.all["cpMainContent_ContactForm_RequiredFieldValidator1"] : document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator1");
cpMainContent_ContactForm_RequiredFieldValidator1.controltovalidate = "cpMainContent_ContactForm_Name";
cpMainContent_ContactForm_RequiredFieldValidator1.errormessage = "Enter your name";
cpMainContent_ContactForm_RequiredFieldValidator1.isvalid = "False";
cpMainContent_ContactForm_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
cpMainContent_ContactForm_RequiredFieldValidator1.initialvalue = "";
var cpMainContent_ContactForm_RequiredFieldValidator2 = document.all ? document.all["cpMainContent_ContactForm_RequiredFieldValidator2"] : document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator2");
cpMainContent_ContactForm_RequiredFieldValidator2.controltovalidate = "cpMainContent_ContactForm_EmailAddress";
cpMainContent_ContactForm_RequiredFieldValidator2.errormessage = "Enter an e-mail address";
cpMainContent_ContactForm_RequiredFieldValidator2.display = "Dynamic";
cpMainContent_ContactForm_RequiredFieldValidator2.isvalid = "False";
cpMainContent_ContactForm_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
cpMainContent_ContactForm_RequiredFieldValidator2.initialvalue = "";
var cpMainContent_ContactForm_RegularExpressionValidator1 = document.all ? document.all["cpMainContent_ContactForm_RegularExpressionValidator1"] : document.getElementById("cpMainContent_ContactForm_RegularExpressionValidator1");
cpMainContent_ContactForm_RegularExpressionValidator1.controltovalidate = "cpMainContent_ContactForm_EmailAddress";
cpMainContent_ContactForm_RegularExpressionValidator1.errormessage = "Enter a valid e-mail";
cpMainContent_ContactForm_RegularExpressionValidator1.display = "Dynamic";
cpMainContent_ContactForm_RegularExpressionValidator1.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
cpMainContent_ContactForm_RegularExpressionValidator1.validationexpression = "\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
var cpMainContent_ContactForm_RequiredFieldValidator3 = document.all ? document.all["cpMainContent_ContactForm_RequiredFieldValidator3"] : document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator3");
cpMainContent_ContactForm_RequiredFieldValidator3.controltovalidate = "cpMainContent_ContactForm_ConfirmEmailAddress";
cpMainContent_ContactForm_RequiredFieldValidator3.errormessage = "Confirm the e-mail";
cpMainContent_ContactForm_RequiredFieldValidator3.display = "Dynamic";
cpMainContent_ContactForm_RequiredFieldValidator3.isvalid = "False";
cpMainContent_ContactForm_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
cpMainContent_ContactForm_RequiredFieldValidator3.initialvalue = "";
var cpMainContent_ContactForm_CompareValidator1 = document.all ? document.all["cpMainContent_ContactForm_CompareValidator1"] : document.getElementById("cpMainContent_ContactForm_CompareValidator1");
cpMainContent_ContactForm_CompareValidator1.controltovalidate = "cpMainContent_ContactForm_ConfirmEmailAddress";
cpMainContent_ContactForm_CompareValidator1.errormessage = "The e-mail addresses";
cpMainContent_ContactForm_CompareValidator1.display = "Dynamic";
cpMainContent_ContactForm_CompareValidator1.evaluationfunction = "CompareValidatorEvaluateIsValid";
cpMainContent_ContactForm_CompareValidator1.controltocompare = "cpMainContent_ContactForm_EmailAddress";
cpMainContent_ContactForm_CompareValidator1.controlhookup = "cpMainContent_ContactForm_EmailAddress";
var cpMainContent_ContactForm_CustomValidator1 = document.all ? document.all["cpMainContent_ContactForm_CustomValidator1"] : document.getElementById("cpMainContent_ContactForm_CustomValidator1");
cpMainContent_ContactForm_CustomValidator1.errormessage = "Enter your home or business phone number";
cpMainContent_ContactForm_CustomValidator1.display = "Dynamic";
cpMainContent_ContactForm_CustomValidator1.isvalid = "False";
cpMainContent_ContactForm_CustomValidator1.evaluationfunction = "CustomValidatorEvaluateIsValid";
cpMainContent_ContactForm_CustomValidator1.clientvalidationfunction = "validatePhoneNumbers";
var cpMainContent_ContactForm_RequiredFieldValidator4 = document.all ? document.all["cpMainContent_ContactForm_RequiredFieldValidator4"] : document.getElementById("cpMainContent_ContactForm_RequiredFieldValidator4");
cpMainContent_ContactForm_RequiredFieldValidator4.controltovalidate = "cpMainContent_ContactForm_Comments";
cpMainContent_ContactForm_RequiredFieldValidator4.errormessage = "Enter a comment";
cpMainContent_ContactForm_RequiredFieldValidator4.display = "Dynamic";
cpMainContent_ContactForm_RequiredFieldValidator4.isvalid = "False";
cpMainContent_ContactForm_RequiredFieldValidator4.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
cpMainContent_ContactForm_RequiredFieldValidator4.initialvalue = "";
var cpMainContent_ContactForm_ValidationSummary1 = document.all ? document.all["cpMainContent_ContactForm_ValidationSummary1"] : document.getElementById("cpMainContent_ContactForm_ValidationSummary1");
cpMainContent_ContactForm_ValidationSummary1.headertext = "Please correct the following errors:";
cpMainContent_ContactForm_ValidationSummary1.showmessagebox = "True";
cpMainContent_ContactForm_ValidationSummary1.showsummary = "False";
//]]>
</script>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="383B18CB" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="Gnui7OIzArbVtULxqQwZb3YaKaS/aQFYMTGefbmycfw8lr04SWT244a6PVd+ETxJ51p0ph2K1A/vBE0EpfzGdVkBZDTgCg/iXrn3ko+9/Pq+1k+qIfq6TLbo8AzwLtTAEr5YEe/O3uHSW++Yf39/+isOFyvuJCVwlN2V5mbMJKiXs3dCejiSFDRixoRB9jPiw1U5LDCehJ7c5BwQJfst0yVnJi8ECAqVaea9ENpd3yPDU14q1iBEMu0YPO1XnUsPYzT4NEaOFQ0aOaZbR3aoziYmOgWaYao8rRBDaYMv9bB+QhibJEd94XLZPKAC8zCH" />
</div>
<script type='text/javascript'>new Sys.WebForms.Menu({ element: 'Menu1', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false });</script>
<script type="text/javascript">
//<![CDATA[
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
//]]>
</script>
</form>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Chrome","requestId":"7913baf45d594175b508e5a702dab5f3"}
</script>
<script type="text/javascript" src="http://localhost:51163/31f867167659470d934491b9b487d82b/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
Thank you for your help.
|
|

February 22nd, 2016, 06:54 AM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just noticed on the ContactForm.ascx.cs file the PhoneHome and PhoneBusiness variables are erroring:
if (!string.IsNullOrEmpty (PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
So on VS the "PhoneHome.Text" and "PhoneBusiness.Text" both have red squiggly line under it. The error reads:
"The name 'PhoneHome' does not exist in the current context"
and
"The name 'PhoneBusiness' does not exist in the current context"
UPDATE:
Just FYI I posted a longer message with all the code on a previous comment however I am guessing because of the size of the comment, it said it will need to approved by moderators before it can be viewed.
|
|

February 22nd, 2016, 11:06 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you try posting just the markup and code behind of the user control?
Imar
|
|

February 23rd, 2016, 05:38 AM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just a note that I continued with the book (as the validation summary is switched back to default later on) so you will see some extra code in there from later chapter. Let me know what you think:
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.IO;
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 (!string.IsNullOrEmpty (PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", Comments.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site. Page: " + PageDescription;
myMessage.Body = mailBody;
myMessage.From = new MailAddress("[email protected]", "Sender Qas");
myMessage.To.Add(new MailAddress("[email protected]", "Receiver Qas"));
myMessage.ReplyToList.Add(new MailAddress(EmailAddress.Text));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Message.Visible = true;
FormTable.Visible = false;
}
}
public string PageDescription { get; set; }
}
|
|

February 24th, 2016, 05:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you post the markup too? There's something that makes PhoneHome unavailable for some reason.
Imar
|
|
 |
|