Recently I had to solve very common problem: When users what to submit the page by clicking on Submit button very often they become inpatient and click the button again which results in another button OnClick event firing (and if you save db record) duplicating records in database.
The most obvious solution is to use JavaScript to disable submit button. Unfortunately this easy solution is not the best because of number of reasons - see Andy Smit's blog entry you don't want to disable buttons after they are clicked here for more details.
So I decided to use another approach : I won't disable button with I will hide it and I show div element with text that would calm user down :). Thus buttons are visisble according ASP.NET but parent HTML element hides them :)
this is the aspx code that declares buttons
<div id="divButtons" style="display:inline;">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="buttons" OnClientClick="SubmitButtonClicked();return true;" OnClick="btnSubmit_Click" style="padding-left: 10; padding-right: 10;"></asp:Button>
<input type="button" value="Cancel" onclick="javascript:top.hidePopWin(false);" style="padding-left: 10; padding-right: 10;"/>
</div>
<div id="divWait" style="display:none;">Note is being saved. Please wait respond from server...</div>
thus asp:Buttons controls fires SubmitButtonClicked(); javascript function before post the form.
Here is the js code:
function SubmitButtonClicked()
{
if (typeof(ValidatorOnSubmit) == "function"){
if (Page_ClientValidate() == false) {
return false; }}
$get("divButtons").style.display = "none";
$get("divWait").style.display = "";
}
UPDATE: The function above is edited according the link below and all validators works as expected. :) Thanks John!
Although the bug I think it is good starting point.
You can see here for alternative solution - http://aspzone.com/blogs/john/articles/207.aspx