Client-Side Event to disable button immediately.
Client-Side Event to disable button immediately.
<script language="javascript"> var c=0; function DisableClick() { var objName = 'Button1'; document.getElementById(objName).disabled=true; c=c+1; msg = 'Please Wait...('+ c +')!'; document.getElementById(objName).value= msg; var t=setTimeout('DisableClick()',1000); } </script>And following button code in body.
Button Control – HTML Button instead of Asp button.
<input id="Button1" name="Button1" onclick="DisableClick();" onserverclick="Button1_Click" runat="server" type="button" value="Submit Payment" />
Note: onclick event is calling javascript client-side function and onserverclick event is calling server-side function which performs actual task.
Server-Side Event to perform actual task
This task can be any as per your logic, for an example I am performing some heavy time consuming task,
you can even make use of Threading concept to minimize code…
protected void Button1_Click(object sender, EventArgs e) { ArrayList a = new ArrayList(); for (int i = 0; i < 10000; i++) { for (int j = 0; j < 1000; j++) { a.Add(i.ToString() + j.ToString()); } } Response.Write("I am done: " + DateTime.Now.ToLongTimeString()); }
Before Button Click
During Button Click
After Task is done
Client-Side Event to disable button immediately.
Reviewed by vishal
on
6:34 AM
Rating: