title: Run javascript first and on success run code behind
body: <p>In Asp page i have below controls. A input textbox ,Imagebutton and a label.</p>
  
  <pre><code>&lt;input id="txtTotamt"  runat="server" type="text" value="0" /&gt;
  &lt;asp:ImageButton ID="Validate" runat="server"  OnClientClick="return validatecontrol();"/&gt;
  &lt;asp:Label ID="lblerror" runat="server"&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>And in javascript in page</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
      function validatecontrol() 
      {
          var valid_amt = document.getElementById("txtTotamt").value;
          if isNaN(valid_amt) == false {
              if(valid_amt % 1 != 0) &amp;&amp; (valid_amt&gt;0){
                  return true;
              }else{
                 document.getElementById("lblerror").innerHTML ="Error";
              }
          }else{
          document.getElementById("lblerror").innerHTML ="Error";
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>In code behind</p>
  
  <pre><code>Protected Sub Validate_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Validate.Click
  //my codes go here
  End Sub
  </code></pre>
  
  <p>I want to validate the content of textbox in a JavaScript and I also have code behind for that button click.I want scrip to be executed first and if the text in input text not proper then code behind should not execute. But it does not work for me. I think the code behind in .net gets triggered before the JavaScript. How it can be solved? Is there any error in my javascript?</p>