I have a page with two sets of controls, with ValidationGroup set differently for each set, but if I attempt to fill in one form correctly, the validators for the other form stop the Click event from firing.
I've noticed that it's behaving normally client-side, but the button then causes a postback event and the server validators do not seem to be honouring the validation groups. I'm unsure what I'm doing wrong. Surely the built in validators all support validation groups on the server side?
Below is a complete standalone example:
<%@ Page Language="C#" %>
<script runat="server">
protected void SubmitButton_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid) label.Text = "OK: " + ((Button)sender).ID.ToString();
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<style>
body { font-family: sans-serif;}
.warning { color: red;}
</style>
</head>
<body>
<form id="f1" runat="server">
<h1>Validator Test</h1>
<asp:Label ID="label" runat="server" Font-Bold="true" ForeColor="Green" EnableViewState="false" /><br />
<div style="width:40%; float:left; height:200px; border:1px solid #eee; padding:15px; margin:5px;">
<h2>Left Form:</h2>
Email: <asp:TextBox ID="leftBox" runat="server" Columns="20" MaxLength="80" Width="160px" ValidationGroup="LEFT" />
<asp:RequiredFieldValidator ID="left2" runat="server" ControlToValidate="leftBox"
ErrorMessage="You must enter a value." ValidationGroup="LEFT">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev8" runat="server" ControlToValidate="leftBox" ValidationGroup="LEFT" Text="*"
ErrorMessage="Email address format is invalid." ValidationExpression="^[\.\-\w]+@([\w\-]+\.)+\w+$" />
<asp:Button ID="LeftSubmitButton" runat="server" Text="Save Left" OnClick="SubmitButton_Click" ValidationGroup="LEFT" />
<asp:ValidationSummary ID="LeftValidationSummary" runat="server" HeaderText="Error:" ValidationGroup="LEFT" CssClass="warning" />
</div>
<div style="width:40%; float:left; height:200px; border:1px solid #eee; padding:15px; margin:5px;">
<h2>Right Form:</h2>
Email: <asp:TextBox ID="rightBox" runat="server" Columns="20" MaxLength="80" Width="160px" ValidationGroup="RIGHT" />
<asp:RequiredFieldValidator ID="rfv9" runat="server" ControlToValidate="rightBox"
ErrorMessage="You must enter an value." ValidationGroup="RIGHT">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev10" runat="server" ControlToValidate="rightBox" ValidationGroup="RIGHT" Text="*"
ErrorMessage="Email address format is invalid." ValidationExpression="^[\.\-\w]+@([\w\-]+\.)+\w+$" />
<asp:Button ID="RightSubmitButton" runat="server" Text="Save Right" OnClick="SubmitButton_Click" ValidationGroup="RIGHT" />
<asp:ValidationSummary ID="RightValidationSummary" runat="server" HeaderText="Error:" ValidationGroup="RIGHT" CssClass="warning" />
</div>
</form>
</body>
</html>
Page.IsValidand expecting it to betrue?