How to prevent ASP:Button from posting back from a jQuery click handler
<p>I have an <code>ASP:Button</code> on a page. It renders as HTML like so:</p>

<pre><code>&lt;input type="submit" name="myButton" value="Do something" 
    onclick="javascript:WebForm_DoPostBackWithOptions(
        new WebForm_PostBackOptions('myButton', '', true, '', '', false, false))"
    id="myButton" /&gt;
</code></pre>

<p>Now I am trying to prevent the default behavior of this button (submitting the form) via a jQuery event handler:</p>

<pre><code>$('#myButton').click(function () { 
    // do some client-side stuff

    if (someCondition) {
        // don't postback!
        return false;
    }
});
</code></pre>

<p>The problem here is that the inline click handler that ASP sticks on the input seems to be executing before the jQuery event handler, every time.</p>

<p>The easiest solution here would be to use a plain <code>input type="button"</code> instead of an <code>ASP:Button</code>, unfortunately <strong>this is not a possibilty</strong> as this <code>ASP:Button</code> does many other things that are required in this scenario.</p>

<p>What would be the best way to prevent the form submission from happening? I've thought of using string manipulation to prepend my handler on the element's <code>onclick</code> attribute, but this seems really dirty. I'd also like to avoid using the <code>OnClientClick</code> as this would require my handler function to be publicly exposed. Is there a better way?</p>
