System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(
"if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append(
"if (Page_ClientValidate() == false) { return false; }} ");
sb.Append(
"this.value = 'Please wait';");
sb.Append(
"this.disabled = true;");
sb.Append(
this.Page.GetPostBackEventReference(this.Button1));
sb.Append(
";");
this.Button1.Attributes.Add("onclick", sb.ToString());


<script type="text/javascript">
function DisableControl(controlId)
{
  document.getElementById(controlId).disabled 
=true;
}

 
function DisableControl_SetTimeout(controlId,interval)
{
  setTimeout(
"DisableControl('" +controlId + "')",interval);
}

 
function btnSave_Click(control)
{
  DisableControl_SetTimeout(control.id,
100);
}

</script>

Private Sub Page_Load(ByVal sender As System.Object,_
        
ByVal e As System.EventArgs) HandlesMyBase.Load
 
  
If Not Me.Page.IsPostBack Then
   
Me.btnSave.Attributes.Add("onclick",_"btnSave_Click(this);")
  
End If
End Sub

<%@ Page Language="VB" %>
<script runat="server">
Dim counter As Integer
Sub Page_Load()
If Session("counter") Is Nothing Then
counter = 0
Else
counter = CInt( Session("counter") )
End If
SafeButton.Attributes.Add("onclick", "disableButton();return true")
End Sub

Sub Process_Click(sender As Object, e As EventArgs)
counter += 1
Session("counter") = counter
Dim i As Long
' 2-second delay
Dim endTime As DateTime = DateTime.Now.AddSeconds(2)
While DateTime.Now < endTime
End While
Label1.Text = counter.ToString()
Label2.Text = DateTime.Now.ToString()
End Sub

Sub ClearCounter_Click(sender As Object, e As EventArgs)
Session("counter") = 0
Label1.Text = Session("counter").ToString()
End Sub
</script>
<html>
<head>
<style>
BODY {
FONT-SIZE: 10pt; FONT-FAMILY: verdana; arial:
}
H2 {
FONT-SIZE: 14pt; FONT-FAMILY: verdana; arial: font-weight:bold
}
</style>
<script language="javascript">
function disableButton()
{
document.form1.SafeButton.style.visibility = "hidden";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>Testing Multiple Posting
</h2>
<p>
Process count:
<asp:Label id="Label1"
runat="server" forecolor="Red" font-bold="True">
</asp:Label>
</p>
<p>
Last clicked: <asp:Label id="Label2" runat="server"></asp:Label>
</p>
<p>
The buttons run a process that takes 2 seconds to run.
</p>
<p>
You can click this button multiple times during processing, potentially
resulting in the process running multiple times:
</p>
<p>
<asp:Button id="UnsafeButton"
onclick="Process_Click"
runat="server"
Text="Unsafe Button">
</asp:Button>
&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
You can click this button only once to run the process:
</p>
<p>
<asp:Button id="SafeButton"
onclick="Process_Click"
runat="server"
Text="Safe Button">
</asp:Button>
</p>
<p>
<asp:LinkButton id="ClearCounter"
onclick="ClearCounter_Click"
runat="server" Text="Clear Counter">
</asp:LinkButton>
</p>
<span id="span1"></span>
</form>
</body>
</html>

 

<script language="javascript">
function disableButton()
{
   message.innerText 
= "Please wait "
   document.form1.SafeButton.style.visibility 
= "hidden";
}


</script>

function disableButton(){  window.setTimeout('disableAfterTimeout()',0);}function disableAfterTimeout(){   document.form1.SafeButton.disabled = true;}


<%@ Page Language="VB" %>
<script runat="server">
Protected sessionGuid As String
Protected viewstateGuid As String
Protected doublePost As Boolean
Protected pageCounter As Integer

Sub Page_Load()
If Session("pageCounter") Is Nothing Then
pageCounter = 0
Session("pageCounter") = 0
Else
pageCounter = CInt(Session("pageCounter"))
End If

Dim newGuid As String = System.guid.NewGuid.ToString
If IsPostBack Then
sessionGuid = Session("guid").ToString()
viewstateGuid = Viewstate("guid").ToString()
If sessionGuid = viewstateGuid Then
doublePost = false
Else
doublePost = true
Response.Write("Page has already been submitted.")
End If
End If
Viewstate("guid") = newGuid
Session("guid") = newGuid
End Sub

Sub Button1_Click(sender As Object, e As EventArgs)
System.Threading.Thread.Sleep(2000) ' Fake a long process
If Not DoublePost Then
pageCounter += 1
Session("pageCounter") = pageCounter
End If
Label1.Text = pageCounter.ToString()
End Sub

</script>

 


<html>
<body>
<form runat="server">
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Button"></asp:Button>
</p>
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
</form>
</body>
</html>