[ Log On ]

asp.net ajax调用的时候防止按钮多次被点击

最近在做"激光" -- ccc的大工程。在用户提交异步请求的时候需要禁止button被多次点击。在这里找到了解决办法,记录一下。
原文地址:http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/
我小小改动了一下,以适合"激光"的用处。我的代码如下:


    
<script type="text/javascript">
         var pbControl = null;
         var prm = Sys.WebForms.PageRequestManager.getInstance();
         prm.add_beginRequest(BeginRequestHandler);
         prm.add_endRequest(EndRequestHandler);
         function BeginRequestHandler(sender, args) {
             pbControl = args.get_postBackElement();  //get the control causing the postback
             if (pbControl != null) {
                 if (pbControl.type == "submit") {
                     pbControl.value = "Saving...";
                     pbControl.disabled = true;
                 }
                 else {
                     pbControl.value = "Updating...";
                     pbControl.disabled = true;
                 }
             }
         }
         function EndRequestHandler(sender, args) {
             if (pbControl != null && pbControl.type == "submit") {
                 pbControl.disabled = false;
                 pbControl = null;
             }
             else {
                 pbControl.value = "";
                 pbControl.disabled = false;
                 pbControl = null;
             }
         }
</script>


Posted by: 幽独梧桐 发表于: 11/17/2009 3:41:39 PM | 3282天15小时26分钟前
简单、方便、有效!
Posted by: natson 发表于: 5/20/2009 4:50:05 AM | 3464天2小时17分钟前
好古老的东西了。。。DOM[emot]shuai[/emot]
Posted by: 3dxfood 发表于: 4/9/2009 6:55:05 AM | 3505天12分钟前
那是,最近感觉精神状态奇差无比
Posted by: 3dxfood 发表于: 3/29/2009 2:35:58 PM | 3515天16小时31分钟前
看了代码就头大。。。

Add your Comment


Supported UBB tags: [b],[u],[i],[color]