No, I did not set any validation group to the validators. Do I need to do this to get the summary validator to work as a showmessagebox?
Main Topics
Browse All TopicsI have a simple webform that uses the validation controls. I have disabled the validation client-side and set the server side validation to be enabled with I call a method EnableValidators().
All this works fine except when I try to add a summaryvalidation control. I can't get the showmessagebox to work for the summary control? I've set showsummary to false and showmessagebox to true.
Here is how I implement the EnableValidators method:
protected void EnableValidators(bool toggle)
{
valcConfirmPassword.Enable
valeEmail.Enabled = toggle;
valrCity.Enabled = toggle;
valrComments.Enabled = toggle;
valrEmail.Enabled = toggle;
valrPalindrome.Enabled = toggle;
valrPassword.Enabled = toggle;
valrReportDate.Enabled = toggle;
valrUsername.Enabled = toggle;
valxPalindrome.Enabled = toggle;
valxPhone.Enabled = toggle;
valxTerms.Enabled = toggle;
valgReportDate.Enabled = toggle;
valxComments.Enabled = toggle;
valxCity.Enabled = toggle;
vals.Enabled = toggle;
}
Then on my button click event handler:
protected void Button1_Click(object sender, EventArgs e)
{
EnableValidators(true);
Page.Validate();
if (Page.IsValid)
{
lblPageValidationStatus.Te
}
else
{
lblPageValidationStatus.Te
}
}
Here is the summary control on the aspx page:
<asp:ValidationSummary ID="vals" runat="server" DisplayMode="List" Enabled="False"
ShowMessageBox="True" ShowSummary="False" />
So, what I'm trying to accomplish is show the message box summary as a popup when the user clicks the submit button as well as show the regular error messages for each control (that already works fine). Only the summaryvalidation control showmessagebox is not working.
Thanks for any help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
it could be that the summary is disabled on first render. since it is only enabled when the Button1_Click event handler is fired, unless the Button1_Click causes the postback and reaches the said event handler, the validator summary is disabled. That is from the client side point of view, it should not validate anything.
hope this makes sense and helps
Okay, I'm still kind of fussy on the page event lifecycle, so forgive my question if I don't understand correctly.
If I enable summaryvalidation control and don't set it to enabled in the code behind then it still doesn't show the popup.
Is that what you mean? Basically, I removed the line: vals.Enabled = toggle.
and changed the control properties to:
<asp:ValidationSummary ID="vals" runat="server" DisplayMode="List" Enabled="True"
ShowMessageBox="True" ShowSummary="False" />
Is this what you meant?
Yes, that's what i meant. If in the *.aspx the validationSummary is enabled and not disabled during the serving of the page (rendering/loading) then the validationSummary should show the alert box.
Is there any chance that you disable it in the code behind while serving/rendering the page?
You seem to be doing it right so it could be possible that in some other part of your code, you disable it or change it's showmessagebox property or change it's validationgroup.
Hi steelheart38,
Thanks for the clarification. I must be disabling the summary control somewhere, but I don't see it? It is probably staring me right in the face.
Here is the full code.
aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm.aspx.cs"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
<html xmlns="http://www.w3.org/1
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="800" cellpadding="5">
<tr>
<td width="150">
<asp:Label ID="lblUsername" runat="server" Text="Username"></asp:Labe
<td width="300">
<asp:TextBox ID="txtUsername" runat="server"></asp:TextB
<td width="350">
<asp:RequiredFieldValidato
</tr>
<tr>
<td width="150">
<asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Labe
<td width="300">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:
<td width="350">
<asp:RequiredFieldValidato
<asp:CompareValidator ID="valcConfirmPassword" runat="server" ErrorMessage="Please re-type your password" ControlToCompare="txtConfi
</tr>
<tr>
<td width="150">
<asp:Label ID="lblConfirmPassword" runat="server" Text="Re-Type Password"></asp:Label></td
<td width="300">
<asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:
<td width="350">
</td>
</tr>
<tr>
<td width="150">
<asp:Label ID="lblEmail" runat="server" Text="Email"></asp:Label><
<td width="300">
<asp:TextBox ID="txtEmail" runat="server"></asp:TextB
<td width="350">
<asp:RequiredFieldValidato
<asp:RegularExpressionVali
</tr>
<tr>
<td width="150">
<asp:Label ID="lblPhone" runat="server" Text="Phone"></asp:Label><
<td width="300">
<asp:TextBox ID="txtAreacode" runat="server" MaxLength="3" Width="30px"></asp:TextBox
<asp:TextBox ID="txtPrefix" runat="server" MaxLength="3" Width="30px"></asp:TextBox
-
<asp:TextBox ID="txtSuffix" runat="server" MaxLength="4" Width="35px"></asp:TextBox
<td width="350">
<asp:CustomValidator
</tr>
<tr>
<td width="150">
<asp:Label ID="lblCity" runat="server">City</asp:L
<td width="300">
<asp:TextBox ID="txtCity" runat="server"></asp:TextB
<td width="350">
<asp:RequiredFieldValidato
<asp:CustomValidator ID="valxCity" runat="server" Display="Dynamic" EnableClientScript="False"
Enabled="False" OnServerValidate="valxCity
</tr>
<tr>
<td width="150">
<asp:Label ID="lblPalindrome" runat="server" Text="Palindrome"></asp:La
<td width="300">
<asp:TextBox ID="txtPalindrome" runat="server"></asp:TextB
<td width="350">
<asp:CustomValidator ID="valxPalindrome" runat="server" ErrorMessage="Not a correct palindrome. Please try again." ControlToValidate="txtPali
<asp:RequiredFieldValidato
</tr>
<tr>
<td width="150">
<asp:Label ID="lblLastReportDate" runat="server" Text="Date of Last Report"></asp:Label></td>
<td width="300">
<asp:TextBox ID="txtReportDate" runat="server"></asp:TextB
<td width="350">
<asp:RequiredFieldVa
<asp:RangeValidator ID="valgReportDate" runat="server" ControlToValidate="txtRepo
Display="Dynamic" EnableClientScript="False"
MaximumValue="12/31/2007" MinimumValue="1/1/2007" Type="Date"></asp:RangeVal
</tr>
<tr>
<td width="150">
<asp:Label ID="lblComments" runat="server" Text="Comments"></asp:Labe
<td width="300">
<asp:TextBox ID="txtComments" runat="server" Rows="4" TextMode="MultiLine" Columns="33"></asp:TextBox
<td width="350">
<asp:RequiredFieldValidato
<asp:CustomValidator ID="valxComments" runat="server" Display="Dynamic" EnableClientScript="False"
Enabled="False" OnServerValidate="valxComm
</tr>
<tr>
<td width="150">
<asp:Label ID="Label1" runat="server" Text="License Agreement"></asp:Label></t
<td width="300">
<asp:TextBox ID="txtLicenseAgreement" runat="server" Rows="4" TextMode="MultiLine" Columns="33"></asp:TextBox
<td width="350">
</td>
</tr>
<tr>
<td width="150">
<asp:Label ID="lblTerms" runat="server" Text="Accept Terms"></asp:Label></td>
<td width="300">
<asp:CheckBox ID="chkTerms" runat="server" Text="I accept" /></td>
<td width="350">
<asp:CustomValidator ID="valxTerms" runat="server" ErrorMessage="You cannot submit the form until you accept the terms of the licence agreement! " OnServerValidate="valxTerm
</tr>
<tr>
<td width="150">
</td>
<td width="300">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
<td width="350">
</td>
</tr>
</table>
</div>
<br />
<asp:Label ID="lblPageValidationStatu
<br />
<br />
<asp:ValidationSummary ID="vals" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" />
</form>
</body>
</html>
codebehind:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using System.Text.RegularExpress
public partial class WebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DisplayLicenseAgreement();
}
}
protected void DisplayLicenseAgreement()
{
txtLicenseAgreement.Text = "Software License Agreement\r\n\r\n" +
"NOTICE TO USER: PLEASE READ THIS AGREEMENT CAREFULLY. BY COPYING," +
"INSTALLING OR USING ALL OR ANY PORTION OF THE SOFTWARE YOU ACCEPT ALL" +
"THE TERMS AND CONDITIONS OF THIS AGREEMENT, INCLUDING, IN PARTICULAR THE" +
"LIMITATIONS ON: USE CONTAINED IN SECTION 2; TRANSFERABILITY IN SECTION 4;" +
"WARRANTY IN SECTIONS 6 AND 7; LIABILITY IN SECTION 8; AND SPECIFIC PROVISIONS" +
"AND EXCEPTIONS IN SECTION 14. YOU AGREE THAT THIS AGREEMENT IS LIKE ANY" +
"WRITTEN NEGOTIATED AGREEMENT SIGNED BY YOU. THIS AGREEMENT IS ENFORCEABLE" +
"AGAINST YOU AND ANY LEGAL ENTITY THAT OBTAINED THE SOFTWARE AND ON WHOSE" +
"BEHALF IT IS USED: FOR EXAMPLE, IF APPLICABLE, YOUR EMPLOYER. IF YOU DO NOT" +
"AGREE TO THE TERMS OF THIS AGREEMENT, DO NOT USE THE SOFTWARE. VISIT" +
"http://www.mysite.com FOR TERMS OF AND LIMITATIONS ON RETURNING THE SOFTWARE" +
"FOR A REFUND\r\n\r\n" +
"Do you accept the terms and conditions stated above?";
}
protected void EnableValidators(bool toggle)
{
valcConfirmPassword.Enable
valeEmail.Enabled = toggle;
valrCity.Enabled = toggle;
valrComments.Enabled = toggle;
valrEmail.Enabled = toggle;
valrPalindrome.Enabled = toggle;
valrPassword.Enabled = toggle;
valrReportDate.Enabled = toggle;
valrUsername.Enabled = toggle;
valxPalindrome.Enabled = toggle;
valxPhone.Enabled = toggle;
valxTerms.Enabled = toggle;
valgReportDate.Enabled = toggle;
valxComments.Enabled = toggle;
valxCity.Enabled = toggle;
}
protected void Button1_Click(object sender, EventArgs e)
{
EnableValidators(true);
Page.Validate();
if (Page.IsValid)
{
lblPageValidationStatus.Te
}
else
{
lblPageValidationStatus.Te
}
}
protected void valxPhone_ServerValidate(o
{
String areacodeRegex = "\\d{3}";
String prefixRegex = "\\d{3}";
String suffixRegex = "\\d{4}";
if ((!Regex.IsMatch(txtAreaco
(!Regex.IsMatch(txtSuffix.
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void valxPalindrome_ServerValid
{
string strPalindrome = args.Value;
string strReverse = "";
for (int intI = strPalindrome.Length - 1; intI >= 0; intI--)
strReverse = strReverse + strPalindrome[intI];
if (strReverse == strPalindrome)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void valxTerms_ServerValidate(o
{
if (chkTerms.Checked)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void valxComments_ServerValidat
{
if (txtComments.Text.Length >= 4 && txtComments.Text.Length <= 100)
{
args.IsValid = true;
}
else if (txtComments.Text.Length < 4)
{
args.IsValid = false;
valxComments.ErrorMessage = "You have entered " + txtComments.Text.Length + " characters. A minimum of 4 characters is required.";
}
else if (txtComments.Text.Length > 100)
{
args.IsValid = false;
valxComments.ErrorMessage = "You have entered " + txtComments.Text.Length + " characters. A maximum of 100 characters is allowed.";
}
}
protected void valxCity_ServerValidate(ob
{
if (txtCity.Text.Length >= 2 && txtCity.Text.Length <= 30)
{
args.IsValid = true;
}
else if (txtCity.Text.Length < 2)
{
args.IsValid = false;
valxCity.ErrorMessage = "You have entered " + txtCity.Text.Length + " characters. A minimum of 2 characters is required.";
}
else if (txtCity.Text.Length > 30)
{
args.IsValid = false;
valxCity.ErrorMessage = "You have entered " + txtCity.Text.Length + " characters. A maximum of 30 characters is allowed.";
}
}
}
Thanks for your help.
Can you try setting these values in all your validators:
EnableClientScript="True"
Enabled="True"
I'm not sure of any other consideration you have but i believe the problem is that all validators are disabled when sent to the client so ValidationSummary really has nothing to validate in the client side. If i'm not mistaken, the alert/message box feature will only work if EnableClientScript is set to true.
Business Accounts
Answer for Membership
by: Edwin_CPosted on 2007-06-26 at 22:28:05ID: 19369949
Did you set any validationgroup to your validators? If so, set it to the validationsummary too.