<p>Details:</p>

<ul>
<li>Only disable after user clicks the submit button, but before the posting back to the server</li>
<li>ASP.NET Webforms (.NET 1.1)</li>
<li>Prefer jQuery (if any library at all)</li>
<li>Must be enabled if form reloads (i.e. credit card failed)</li>
</ul>

<p>This isn't a necessity that I do this, but if there is a simple way to do it without having to change too much, I'll do it. (i.e. if there isn't a simple solution, I probably won't do it, so don't worry about digging too deep)</p>

[{'answer_id': 46082, 'author': 'Jimmy', 'author_id': 4435, 'author_profile': 'https://Stackoverflow.com/users/4435', 'pm_score': 1, 'selected': False, 'text': "<p>in JQuery:</p>\n\n<pre><code>$('#SubmitButtonID').click(function() { this.disabled = true; });\n</code></pre>\n"}, {'answer_id': 46138, 'author': 'SpoonMeiser', 'author_id': 1577190, 'author_profile': 'https://Stackoverflow.com/users/1577190', 'pm_score': 5, 'selected': True, 'text': '<p>For all submit buttons, via JQuery, it\'d be:</p>\n\n<pre><code>$(\'input[type=submit]\').click(function() { this.disabled = true; });\n</code></pre>\n\n<p>Or it might be more useful to do so on form submission:</p>\n\n<pre><code>$(\'form\').submit(function() {\n    $(\'input[type=submit]\', this).attr("disabled","disabled");\n});\n</code></pre>\n\n<p>But I think we could give a better answer to your question if we knew a bit more about the context.</p>\n\n<p>If this is an ajax request, then you\'ll need to make sure you enable submit buttons again on either success or failure.</p>\n\n<p>If this is a standard HTTP form submission (aside from disabling the button with javascript) and you\'re doing this to safe guard from multiple submissions of the same form, then you ought to have some sort of control in the code that deals with the submitted data, because disabling a button with javascript might not prevent multiple submissions.</p>\n'}, {'answer_id': 46139, 'author': 'spoulson', 'author_id': 3347, 'author_profile': 'https://Stackoverflow.com/users/3347', 'pm_score': 0, 'selected': False, 'text': '<p>There are three ways to submit a form that should be covered.  Use both David McLaughlin\'s and Jimmy\'s suggestions.  One will disable the submit button form element while the other disables the basic HTML form submit.</p>\n\n<p>For the third, these won\'t disable Javascript from doing a form.submit().  The <code>OnSubmit="return false"</code> method only applies when a user clicks the submit button or presses Enter in a input form element.  Client side scripting will need to be handled as well.</p>\n'}, {'answer_id': 46148, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m guessing that you don\'t want them to hit the submit button more than once while the submit is processing.</p>\n\n<p>My approach has been to just hide the button entirely and display some sort of status indicator (animated gif, etc) instead.</p>\n\n<p>Here\'s a very contrived example (it\'s technically in prototype but I think a jquery version would be very similar):</p>\n\n<pre><code>&lt;html&gt;\n    &lt;head&gt;\n        &lt;script type="text/javascript" src="include/js/prototype.js"&gt;&lt;/script&gt;\n\n        &lt;script type="text/javascript"&gt;\n            function handleSubmit()\n            {\n                $(\'submit\').hide();\n                $(\'progressWheel\').show();\n                return true;\n            }\n        &lt;/script&gt;\n    &lt;/head&gt;\n    &lt;body&gt;\n        &lt;img src="include/images/progress-wheel_lg.gif" id="progressWheel" style="display:none;"/&gt;\n        &lt;input type="submit" name="submit" id="submit" value="Submit" onclick="handleSubmit();"/&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 249428, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 0, 'selected': False, 'text': '<p>How about</p>\n\n<p><strong>Code behind</strong>:</p>\n\n<p>btnContinue3.Attributes.Item("onclick") = "disableSubmit()"    </p>\n\n<p><strong>Javascript</strong>:</p>\n\n<pre><code>function disableSubmit() {\n    document.getElementById(\'btnContinue3\').onclick = function() { \n        alert(\'Please only click once on the submit button!\'); return false;\n    };\n}\n</code></pre>\n\n<p>This doesnt solve the problem of what happens if the postback times out, but other than that it worked for me.</p>\n'}, {'answer_id': 249480, 'author': 'Rune Grimstad', 'author_id': 30366, 'author_profile': 'https://Stackoverflow.com/users/30366', 'pm_score': 1, 'selected': False, 'text': '<p>On thing to be aware of is that you should not disable the button before the form is submitted. If you disable the button using javascript in the OnClick event you may lose the form submit.</p>\n\n<p>So I would suggest you hide the button using javascript by placing an image above it or by moving the button out of the visible range. That should allow the form submit to proceed normally.</p>\n'}, {'answer_id': 249530, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 3, 'selected': False, 'text': '<p>You could do something like this:</p>\n\n<pre><code>$(\'form\').submit(function() {\n    $(this)\n        .find(":submit,:image")             // get all the submit buttons\n        .attr({ disabled : \'disabled\' })    // disable them\n        .end()                              // go back to this form\n        .submit(function() {                // change the onsubmit to always reject.\n            return false;\n        })\n    ;\n});\n</code></pre>\n\n<p>Benefits of this:</p>\n\n<ul>\n<li>It will work with all your forms, with all methods of submission:\n\n<ul>\n<li>clicking a submit element</li>\n<li>pressing enter, or</li>\n<li>calling <code>form.submit()</code> from some other code</li>\n</ul></li>\n<li>It will disable all submit elements:\n\n<ul>\n<li><code>&lt;input type="submit"/&gt;</code></li>\n<li><code>&lt;button type="submit"&gt;&lt;/button&gt;</code></li>\n<li><code>&lt;input type="image" /&gt;</code></li>\n</ul></li>\n<li>it\'s really short.</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/46079', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1446/']