I have several required fields and regex's on my form. The validation is fired on a button click. When the button is clicked, the error messages are showing where the asp:RequiredField
are declared and not in the validation summary. Here is my code:
Validation Summary:
<asp:ValidationSummary id="mySummary" DisplayMode="List" HeaderText="Error:" EnableClientScript="true" ShowSummary="true" runat="server" ValidationGroup="valGroup" />
Required Fields/Regex:
<!-- Required -->
<asp:RequiredFieldValidator ID="reqField1" ControlToValidate="txtSomething" ErrorMessage="Something is required" runat="server" Display="Static" InitialValue="" ValidationGroup="valGroup" />
<!-- Regex -->
<asp:RegularExpressionValidator runat="server" id="regexField1" ControlToValidate="txtSomething"
ErrorMessage="Something in the wrong format." ValidationExpression="^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$" ValidationGroup="valGroup">
</asp:RegularExpressionValidator>
Button:
<asp:LinkButton ID="btnValidate" runat="server" CausesValidation="True" ValidationGroup="valGroup" >Validate</asp:LinkButton>
Any suggestions?
Best Answer
It's hard to tell from this, as it does look like it's setup correctly to me. The only way to debug is to check the
Page.Validators
collection, find the validators in there, and ensureIsValid
is false for those guys. All theValidationSummary
does is check this collection, and for any with a matching validation group, if theIsValid
property is false, adds it to the list that's rendered out.