Hello folks,

I have a simple form with a button. The button is server control.

in the OnClientclick event of the button control, I am actually doing some validations. If the validation fails, the onclick event should not be executed. How can I control this?

In the code below, PerformChecks() function gets fired first and alert message pops up fine. But immediately onclick event (which is handled on the server) gets triggered. if the check in PerformChecks fail, how can I suppress onclick event?

Code:
 <asp:Button ID="ButtonRun" runat="server" Text="Go" 
                    onclick="ButtonRun_Click" OnClientClick="PerformChecks();" Width="57px"  />


function PerformChecks() {
                 
                 
  var checkboxCollection = document.getElementById('<%=CheckBoxListInstruments.ClientID %>').getElementsByTagName('input');

  for (var i = 0; i < checkboxCollection.length; i++) {

          if (checkboxCollection[i].checked)
               return;
  }

   window.alert("Please check atleast one checkbox");
                    
   }                  
   }