0

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?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Barry Tormey
  • 2,966
  • 4
  • 35
  • 55
  • Is your validation summary inside some other element that keeps it from displaying? Your code looks fine. – MikeSmithDev May 20 '13 at 15:41
  • No, if that were the case, then I wouldn't be able to see the error messages at, because they would be going to the validation summary. In my case, the errors are showing, just not in the summary box. – Barry Tormey May 20 '13 at 15:56
  • What I meant was, say your validation summary is in a `div` with `display:none;` or something. This wouldn't affect your other error messages at all. If your error messages are showing, then your summary messages should also be showing... which made me wonder if it is displaying somewhere and you just can't see it. – MikeSmithDev May 20 '13 at 16:12
  • Oh! Yes, it does seem to be displaying in a `div` with `display:none`. But I am unsure why? When I edit out the style in the CSS with Firebug, though, it still does not show the errors in the summary. – Barry Tormey May 20 '13 at 16:17
  • Well the div itself that the code generates may initially have a `display:none`... just wondering if it is inside an element you created that is also `display:none`. But yes, when inspecting the element after validation failure in something like firebug you should be able to see that actual inner text whether it is hidden or not (not like view source)... so if you don't see that... IDK. – MikeSmithDev May 20 '13 at 16:22

1 Answers1

0

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 ensure IsValid is false for those guys. All the ValidationSummary does is check this collection, and for any with a matching validation group, if the IsValid property is false, adds it to the list that's rendered out.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Thank you Brian, I looked into this and the validation groups are all the same between the button, validators, and summary. The 'isValid' property of the validators is set to false for the ones that are not valid. This one is really puzzling me... – Barry Tormey May 20 '13 at 16:09
  • I can understand why then, because if that is setup, then yes, it should work... the next thing to try would be disable client script, and see if it validates correctly on server-side postback, to see if it's a client-side validation issue... – Brian Mains May 20 '13 at 19:36