I'm writing this answer only because I'm using html buttons with ASP.NET WebForms and I couldn't find solution why should I replace my piece of code with working examples. Here is solution why it is not working. Hope it will help you to understand the issue like checking it helped me. This is my first post, so sorry for style.
<button type="button" id="buttonAddOrEdit" class="btn btn-success" runat="server" onclick="return myValidate()" onserverclick="buttonAddOrEdit_ServerClick">Zapisz</button>
And javascript function:
function myValidation() {
if (validator.form()) {
//Project logic
return true;
}
else return false;
};
Using client side click after correct validation wasn't triggering event on server side that was binded to button. Solution mentioned to change piece of code to:
onclick="if(!myValidation()) return;"
Works because of way that html rendered on page with onserverclick is created. Onserverclick on html button is being replaced by __doPostBack method from javascript. Fullcode of html button rendered on client side looks this way:
<button onclick="return myValidation(); __doPostBack('ctl00$PortalContent$buttonAddOrEdit','')" id="ctl00_PortalContent_buttonAddOrEdit" type="button" class="btn btn-success">Zapisz</button> Błąd składni
And after replacing it with if statment.
<button onclick="if(!myValidation()) return; __doPostBack('ctl00$PortalContent$buttonAddOrEdit','')" id="ctl00_PortalContent_buttonAddOrEdit" type="button" class="btn btn-success">Zapisz</button>
Working with return myValidate(); won't tirgger event because it returns before __doPostBack.
Following code will allow you to add some another code to button if neccessary and won't cause any issues.