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 October 9th, 2012, 03:57 AM
Registered User
 
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9

2 questions:

1. In chapter 9 (Validation) Im supposed to use a CustomValidator, however it seems like the dynamic property doesn't work. Whenever i tab after filling in a t phone number, it just keep showing the "*" like nothing's changed..

It's only responding to when i click the "Send" button...

So i ask..... Can I somehow make the customvalidator as dynamic as all the other validators?

2. Im supposed to show my errors when i validate things in a messagebox.. However, it's not showing... Why is that? (the code is correct, and I've checked on the internet where i've found similar cases of people saying it's not working..

Any help is appreciated..
 
Old October 9th, 2012, 04:29 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 there,

If I understand you correctly, item 1 is by design. Because the custom validator is attached to multiple fields, it doesn't get triggered when you tab away from one of them.

For question 2: can you post your code? And have you tried different brwosers?

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 October 9th, 2012, 04:53 AM
Registered User
 
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 9

Here is my validationSummary..


<td colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Please correct the follow errors before you press the Send button"
ShowMessageBox="true" ShowSummary="false" />
</td>


It works quite fine with showsummary = true, but i can't seem to get it to show the messagebox...


p.s And yes i've tried Chrome, IE and firefox.. It's the same all over.


and the first thing with my customvalidator... It works, it was just a technical detail I was wondering about..
 
Old October 9th, 2012, 08:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you show the rest of the code of the page / user control as well?

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 October 10th, 2012, 09:03 AM
Registered User
 
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Smile hi Imar

sure thing..

User Control page (ControlForm)

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ContactForm.ascx.vb" Inherits="Controls_ContactForm" %>
<style type="text/css">
.style1
{
width: 100%;
}

td
{
width: 250px;
}
.style2
{
width: 153px;
}
.style3
{
height: 35px;
}
.style4
{
width: 153px;
height: 35px;
}
</style>
<script language="text/javascript">

function ValidatePhoneNumbers(source, args)
{
var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
var txtPhoneBusiness = document.getElementById('<%= txtPhoneBusiness.ClientID %>');

if (txtPhoneHome != '' || txtPhoneBusiness != '')
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
</script>

<table class="style1">
<tr>
<td colspan="3" style="width:100%;" >
<span style="font-size:xx-large;font-weight:bold;">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 class="style2">
<asp:TextBox ID="txtName" runat="server" Width="162px"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtName" ErrorMessage="Please enter your name">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Your e-mail address</td>
<td class="style2">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="162px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtEmailAddress" Display="Dynamic"
ErrorMessage="Please enter an e-mail address">*</asp:RequiredFieldValidator>
<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 class="style3">
Your e-mail address again</td>
<td class="style4">
<asp:TextBox ID="txtEmailAddressConfirm" runat="server" Width="162px"></asp:TextBox>
</td>
<td class="style3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtEmailAddressConfirm" Display="Dynamic"
ErrorMessage="Please confirm the e-mail address">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtEmailAddressConfirm" ControlToValidate="txtEmailAddress"
Display="Dynamic" ErrorMessage="Please retype the e-mail address">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td>
Home phone number</td>
<td class="style2">
<asp:TextBox ID="txtPhoneHome" runat="server" Width="162px"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Please enter your home or business number"
ClientValidationFunction="ValidatePhoneNumbers" Display="Dynamic"
ValidateEmptyText="True">*</asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Business phone number</td>
<td class="style2">
<asp:TextBox ID="txtPhoneBusiness" runat="server" Width="162px"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Comments</td>
<td class="style2">
<asp:TextBox ID="txtComments" runat="server" Height="69px" TextMode="MultiLine"
Width="404px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtComments" Display="Dynamic"
ErrorMessage="Please enter a comment">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td >
&nbsp;</td>
<td class="style2" >
<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 follow errors before you press the Send button"
ShowMessageBox="false" ShowSummary="true" />
</td>
</tr>
</table>


About Contact page

<%@ Page Title="Contact" Language="VB" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="false" CodeFile="Contact.aspx.vb" Inherits="Contact" %>

<%@ Register src="../Controls/ContactForm.ascx" tagname="ContactForm" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<uc1:ContactForm ID="ContactForm1" runat="server" />
</asp:Content>




Another thing..

How do you look up your internet provider, if you choose not to call them?

Do you by chance know that ? :)

thanks in advance..
 
Old October 10th, 2012, 09:31 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

There's an error in your JavaScript code:

Code:
 
 if (txtPhoneHome != '' || txtPhoneBusiness != '')
You should access the value property of these controls liek this instead:

Code:
 
 if (txtPhoneHome.value != '' || txtPhoneBusiness.value != '')
This causes JavaScript errors which in turns prevents the alert box from being shown.

Quote:
How do you look up your internet provider, if you choose not to call them?
I have no idea what you're asking.

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 October 11th, 2012, 06:29 PM
Registered User
 
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default hi Imar

Hi Imar

The javascript didn't fail as far as i know, since it's showing the errormessage in the showsummary, although i tried to add ".value" behind the variables, and it didn't help..


forget about the last question. It was regarding emails and further down in the chapter..
 
Old October 12th, 2012, 06:12 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 there,

I think you see the summary *after* a postback. That is, your JavaScript is somehow broken so client side validation doesn't work properly. Then the page posts back, and the summary with errors is generated by the server side validation. To see if that's the case, set a breakpoint in the code behind, hit F5 to debug and see what happens. Chapter 17 has more details.

I can see a few things with your client script that causes this error. First, the language attribute on the <script> element which should be a type attribute instead. Secondly, the closing } is missing. And finally, the value attributes are missing. Here's the full code that should work:

Code:
 
<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>
Once you make this change, you'll see that the message box will work.

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 October 12th, 2012, 07:41 AM
Registered User
 
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Hi Imar

I changed all of that and it still didn't work.

Could it have something to do with the fact that im using ASP.NET 4 instead of 3.5? Cause earlier that caused an error for my menu properties..


Thank you..


Edit..

I have no idea why, but i tried changing it again today, and suddenly it worked.. I'm an idiot for not seeing this...

Thank you so much Imar everything works now. You have been a great help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - Code Download Missing for this Chapter dbaechtel BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 August 11th, 2009 11:02 AM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





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