<Asp: button runat ="Server"Id ="BTN"TEXT ="Button"Onclick ="Aa_click"/>
Public VoidPage_load (Object OBJ, eventargs E)
{
BTN. Attributes. Add ("Onclick","State = true ;");
Stringbuilder sb =NewStringbuilder ();
SB. append ("If (! State) return ;");
SB. append ("Var button = Document. getelementbyid ('btn ');");
SB. append ("Button. value = 'Please wait ...';");
SB. append ("Document. Body. style. cursor = 'wait ';");
SB. append ("Button. Disabled = true ;");
StringStrscript ="<SCRIPT>";
Strscript = strscript +"Var state = false ;";
// Bind the function to the onbeforeunload event on the page:
strscript = strscript + " window. attachevent ('onbeforeunload', function () {" + sb. tostring () + "});" ;
Strscript = strscript +"</"+"Script>";
Page. registerstartupscript ("Onbeforeunload", Strscript );
}
Protected VoidAa_click (ObjectSender, eventargs E)
{
// Simulate button processing for a long time
system. threading. thread. sleep (2000);
Response. Write ("<SCRIPT> alert ('bbbbbb !! ');"+"</"+"Script>");
}