Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 26th, 2008, 09:27 AM
Authorized User
Points: 180, Level: 3
Points: 180, Level: 3 Points: 180, Level: 3 Points: 180, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Milan, , Italy.
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default Chap. 9 - ValidationSummary

Hi all,
in a test page with several validation controls, I put also a ValidationSummary to have pop-up tells some errors occurs, but when I run the page (with errors), none pop-up get up.
My code is this:

<asp:ValidationSummary runat="server"
  ShowMessageBox="true"
  ShowSummary="true"
  HeaderText="Errors on input" />

Why this appear?

Thanks in advance.

Luigi

Reply With Quote
  #2 (permalink)  
Old May 26th, 2008, 09:38 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Hi Luigi,

I am not sure what the problem is. Are you getting the alert box or not?

"Why this appear?" seems to suggest you get the box, which is the right behavior when ShowMessageBox is set to true.

If you're not getting the alert box, can you show us the rest of the code for the page?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old May 26th, 2008, 09:43 AM
Authorized User
Points: 180, Level: 3
Points: 180, Level: 3 Points: 180, Level: 3 Points: 180, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Milan, , Italy.
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default

It's the exact opposite Imar, the pop-up don't appears.

And I don't know why.

L

Reply With Quote
  #4 (permalink)  
Old May 26th, 2008, 10:34 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Quote:
quote:If you're not getting the alert box, can you show us the rest of the code for the page?
Can you post the relevant code?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #5 (permalink)  
Old May 28th, 2008, 12:16 PM
Authorized User
 
Join Date: Apr 2008
Location: Rockville, MD, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After I set the ShowMessagebox to true and the Show Summary to false the the message box does not display when there are errors on the page. I have included the code for the control and the page. Thank you for your assistance.

C# code from the Control
 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (txtPhoneHome.Text != string.Empty || txtPhoneBusiness.Text != string.Empty)
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }
Control Code Source

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<style type="text/css">
    .style1
    {
        width: 100%;
    }
    .style2
    {
        width: 314px;
    }
</style>

<script type="text/javascript">
function ValidatePhoneNumbers(source, args)
{
    var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
    var txtBusinessPhone = document.getElementById('<%= txtPhoneBusiness.ClientID %>');
    if (txtPhoneNumber.value !=' ' || txtPhoneBusiness.Value != ' ')
    {
        args.IsValid = true;
    }
    else
    {
        args.IsValid = false;
    {


 }
</script>
<table class="style1">
    <tr>
        <td colspan="3">
                       <h1>Get in touch with us</h1><p>Use the form below to get in touch with us.&nbsp;
                       Enter your name, e-mail address and your home or business phone number so we may contact you.</p></td>
    </tr>
    <tr>
        <td style="font-weight: 700">
            Your name</td>
        <td class="style2">
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                ControlToValidate="txtName" ErrorMessage="Please enter your name">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server" Text="Your e-mail address"
                Font-Bold="True"></asp:Label>
        </td>
        <td class="style2">
            <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>
            <asp:Label ID="Label3" runat="server" Font-Bold="True"
                Text="Your e-mail address again"></asp:Label>
        </td>
        <td class="style2">
            <asp:TextBox ID="txtEmailAddressConfirm" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                Display="Dynamic" ErrorMessage="Please confirm the e-mail address"
                ControlToValidate="txtEmailAddressConfirm">*</asp:RequiredFieldValidator>
            <br />
            <asp:CompareValidator ID="CompareValidator1" runat="server" Display="Dynamic"
                ErrorMessage="Please re-type the e-mail address"
                ControlToCompare="txtEmailAddress" ControlToValidate="txtEmailAddressConfirm">*</asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label4" runat="server" Font-Bold="True"
                Text="Your home phone number"></asp:Label>
        </td>
        <td class="style2">
            <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>
            <asp:Label ID="Label5" runat="server" Font-Bold="True"
                Text="Business phone number"></asp:Label>
        </td>
        <td class="style2">
            <asp:TextBox ID="txtPhoneBusiness" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label6" runat="server" Font-Bold="True" Text="Comments"></asp:Label>
        </td>
        <td class="style2" colspan="1">
            <asp:TextBox ID="txtComments" runat="server" Height="50px"
                TextMode="MultiLine" Width="350px"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                Display="Dynamic" ErrorMessage="Please enter a comment"
                ControlToValidate="txtComments">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td class="style2">
            <asp:Button ID="btnSend" runat="server" Font-Bold="True" 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>
Reply With Quote
  #6 (permalink)  
Old May 28th, 2008, 04:38 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

You got your curly braces mixed up. This:
Code:
else
{
  args.IsValid = false;
{
should be:
Code:
else
{
  args.IsValid = false;
}
Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #7 (permalink)  
Old May 28th, 2008, 09:58 PM
Authorized User
 
Join Date: Apr 2008
Location: Rockville, MD, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your assistance Imar. Correcting the brace issue resolved the script warning issue and allowed the Alert box to display as it should when errors exists.

Cheers,

Brian
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 2 Solution broadiea BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 19th, 2007 04:56 PM
validationsummary prob leo_vinay ASP.NET 1.0 and 1.1 Basics 1 October 7th, 2005 12:39 PM
chap 15 manal_sag BOOK: Beginning ASP 3.0 2 July 10th, 2005 03:29 AM
help in chap 15 manal_sag BOOK: Beginning ASP 3.0 2 May 25th, 2005 02:59 AM
ValidationSummary vmaila ASP.NET 1.0 and 1.1 Basics 0 September 14th, 2003 11:08 AM



All times are GMT -4. The time now is 03:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.