0

我在update panel.

我想要它,所以当用户单击按钮时,Please Wait...文本显示为按钮文本,并且该按钮被禁用,直到回发完成。我写了这段代码:

$('#Button2').on("click", function (e) {
                $("#Button2").val("Please Wait");
                $('#Button2').attr('disabled', 'disabled');
});

问题是当按钮被禁用时,它的事件不会在服务器端引发。我怎么解决这个问题?

4

5 回答 5

4

您是否使用 jQuery.ajax 函数来触发服务器调用?如果是这样,那么在“beforeSend”键中更改按钮文本并禁用。

$.ajax({
    .....
    beforeSend: function(){
     $("#Button2").val("Please Wait");
     $('#Button2').attr('disabled', 'disabled');
    }
    .....
});
于 2012-04-26T06:04:44.337 回答
2
$('#Button2').on("click", function (e) {
                $("#Button2").text("Please Wait");
                $('#Button2').attr('disabled', 'disabled');
               //your ajax function here
     $.ajax({
            url:'your url',
            data : ({/*data to send***/  }),
            method : 'POST',

            success: function(msg){
                 $('#Button2').removeAttr('disabled');
           }
    });
             //end ajax


});
于 2012-04-26T06:04:21.530 回答
1

您可以在 jQuery 中使用 .attr 和 .html 函数。

$('#btn').click(function(){
    $(this).html('Saving...'); //this changes the html to Saving...
    $(this).attr('disabled', true); //this will disable the button onclick
});

这是一个示例小提琴:http: //jsfiddle.net/stan255/cpLqK/1/

希望这可以帮助。

  • 斯坦利
于 2014-03-06T01:29:42.817 回答
0

在您的 onClick 函数中,尝试先进行 ajax 调用,然后再禁用该按钮。由于它是异步调用,因此下一行脚本应在调用时禁用该按钮。在您拨打电话后的回调中,您可以重新启用您的按钮。

于 2012-04-26T06:04:04.123 回答
0

你应该在禁用按钮后调用服务器事件。为此你应该使用ClientScript.GetPostBackEventReference(bt1, null)

请参阅此链接:在异步回发的更新面板中禁用按钮

于 2012-04-26T06:57:14.670 回答