title: Stop postback after alert by javascript in ASP.NET Code
body: <p>I have a textbox and a button, on button's clientClick I call javascript function and there is also server side coding.</p>
  
  <p>Problem is, the page gets post back even if I have return False in the javascript.</p>
  
  <p>Here is my javascript function:</p>
  
  <pre><code>function checkALphaNumericFormat(str) {
  
              //get previous value before editing
              var txtUserId = document.getElementById('&lt;%=txtUserId.ClientID%&gt;');            
              var userId = txtUserId.value;
              var patternAlphaNumeric = /^[A-z0-9]+$/gi;
              var match = userId.match(patternAlphaNumeric);
  
              //Check Null values
              if (txtUserId.value != null &amp;&amp; txtUserId.value != "") {
  
                  //Check for AlphaNumeric values for User Id
                  if (match == null) {
                      alert("Please provide valid AlphaNumeric User Id");
                      return false  ;
                  }
  
                  return false ;
              }
              else {
                      alert("User Id field should not be null");
                      return false  ;               
              }              
              return false ;
          }
  </code></pre>
  
  <p>and I am calling this function on my Form as:</p>
  
  <pre><code>&lt;asp:Button runat="server" ID="btnCreate"  CssClass="loginButton" style="margin:0px 0px 1px 30px;" OnClientClick ="return checkALphaNumericFormat(this.value);"  Text="CREATE" /&gt;
  </code></pre>