I have a ValidationSummary control that was initially working with all my validation controls at the beginning, however, later on when I assigned my validation controls to groups, ie, give them a group name in the ValidationGroups
attribute, it does not seem to show the error messages of the validation controls that fails the validation on the server side. I'm using the call to Page.Validate()
to validate all the controls on the server side. Has anyone ran into this issue before?
I experimented a bit with a simple page and noticed that this happens when you assign a CustomerValidator to a group but the problem goes away without the group.
Here is Start.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Start.aspx.cs" Inherits="WebApplication3.Start" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation ="true" OnClick="Button1_Click" style="height: 26px"/>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ValidationGroup="Group1" Display="None" ErrorMessage="RequiredFieldValidator1"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ValidationGroup="Group2" Display="None" ErrorMessage="RequiredFieldValidator2"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox2" Display="None" ValidationGroup="Group2" ErrorMessage="Message for display in validation summary" OnServerValidate="cusCustom_ServerValidate"></asp:CustomValidator>
</div>
</form>
</body>
</html>
Here is Start.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
{
public partial class Start : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
{
e.IsValid = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
Page.Validate();
}
}
}