1

I have a ValidationSummary on client side (which should be called by asp:LinkButton) that check my RequiredFieldValidator and CustomValidator :

<asp:ValidationSummary 
    ID="valSum" 
    runat="server" 
    CssClass="label" 
    HeaderText="There are these errors:" 
    ShowSummary="False" 
    ShowMessageBox="True" 
    EnableClientScript="True" 
    DisplayMode="BulletList">
</asp:ValidationSummary>

and I need, if there are the errors (so there are empty fields or the custom validators fail) call another javascript function.

I really hope that this is possible on .NET 3.5, right?

I've read a similar question on SO here, but is not clear at all.

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

8

Place this script at the page's end:

<script type="text/javascript">
     var originalValidationSummaryOnSubmit = ValidationSummaryOnSubmit;
     ValidationSummaryOnSubmit = function (validationGroup) {
          originalValidationSummaryOnSubmit(validationGroup);

          if (Page_IsValid === false) {
               alert("boo!");
          }
     }
</script>
Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • Excelent! Solved my problem! One question: `validationGroup` is the only parameter of `ValidationSummaryOnSubmit`? How can I get the name/id of the button that had trigger the validation? – Vinicius Garcia Aug 11 '15 at 14:50
4

Yes this is possible. You will need to change the OnClientClick property of your linkbutton and/or other controls causing the validation to perform. Also put your CausesValidation property to false.

  <asp:LinkButton ID="lnkButton1" runat="server" CausesValidation="false" OnClientClick="return DoValidation('');" ... />

Javascript function:

 function DoValidation(validationGroup) {
      var isValid = Page_ClientValidate(validationGroup);
      if (!isValid){
         isValid = DoSomethingElse();
      }
     return isValid;
 }

If you want to only validate a group you can pass the name of the group to the 'DoValidation' function.

  <asp:LinkButton ID="lnkButton1" runat="server" CausesValidation="false" OnClientClick="return DoValidation('NameOfGroup');" ... />
Martijn B
  • 4,065
  • 2
  • 29
  • 41