Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 服务器事件后禁用和启用jquery中的按钮_Asp.net_Jquery - Fatal编程技术网

Asp.net 服务器事件后禁用和启用jquery中的按钮

Asp.net 服务器事件后禁用和启用jquery中的按钮,asp.net,jquery,Asp.net,Jquery,我需要在单击期间禁用该按钮,并需要在服务器端事件完成后启用 现在我的代码是这样的 <script src="../Scripts/jquery-1.3.2.js" type="text/javascript"></script> <script type ="text/javascript" > $(document).ready(function(){ $('.saveButton').bind("click", function(e)

我需要在单击期间禁用该按钮,并需要在服务器端事件完成后启用 现在我的代码是这样的

<script src="../Scripts/jquery-1.3.2.js" type="text/javascript"></script>   
<script  type ="text/javascript" >


$(document).ready(function(){
    $('.saveButton').bind("click", function(e) {
        $(this).attr("disabled", "true");
        return true; //causes the client side script to run.
    });
});
</script>
//this  works  finr  for disableing the   button
//how  to enable  the  button  from disabled  to enable  after my server  side  event as  executed

<asp:Button ID="Button1" runat="server"  CssClass="saveButton"  Text="Button" 
        onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server"  CssClass="saveButton"  Text="Button" 
            onclick="Button2_Click" /> 

//Server   side  events
protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
    }
    catch()
    {
    }
    finally
    {
        //once  my    control  reaches  here  i need   to enable  my save  from disabled to enabled stae 
        // can we  do this in jQuery
    }
}

$(文档).ready(函数(){
$('.saveButton').bind(“单击”,函数(e){
$(this.attr(“disabled”、“true”);
return true;//使客户端脚本运行。
});
});
//这适用于禁用按钮的finr
//如何在我的服务器端事件执行后启用从禁用到启用的按钮
//服务器端事件
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
尝试
{
}
捕获()
{
}
最后
{
//一旦我的控件到达这里,我需要启用从禁用状态到启用状态的保存
//我们可以在jQuery中这样做吗
}
}
查找过去2天中的此代码 这方面的任何解决方案都很好,谢谢 谢谢

您可以使用
按钮1\u单击事件上的方法,从服务器端添加客户端脚本:

var enableButton = "$('.saveButton').removeAttr('disabled');";
Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "EnableButton",
                                            enableButton, true); 

我认为这里的核心问题是你对页面生命周期的理解,你可能想在这里读一下

看起来您不一定要将页面发回。考虑使用jQuery Ajax更新服务器,并在该回调中重新启用按钮。 或者,这将在5秒后重新启用按钮(在回发后(希望如此!))

或者,在按钮末尾,单击事件写入文本控件,如下所示: “$(文档).ready(函数(){$('jQueryButtonSelector').removeAttr('disabled');})”


或者使用response.write()执行同样的操作。

我遇到了问题,其他答案在禁用后没有调用服务器端事件,为了解决这个问题,我异步禁用了按钮

客户端

<asp:Button runat="server" ID="submitButton" ValidationGroup="DynamicForm" OnClientClick="disableButton(this);" />
<script>
    function disableButton(sender) { // Disable to prevent duplicate submission. Enabled in code behind
        if (Page_ClientValidate("DynamicForm")) {
            setTimeout(function () { $('#<%= submitButton.ClientID%>').attr("disabled", "true"); }, 0); // Asynchronously disable, otherwise disabled button won't submit first time
        }
     }
</script>

嘿,这里发生的事情是,一旦我单击按钮,按钮就会被禁用。但是现在它不会只调用我的服务器端事件,即受保护的无效按钮1\u单击(对象发送方,EventArgs e){///my code}
<asp:Button runat="server" ID="submitButton" ValidationGroup="DynamicForm" OnClientClick="disableButton(this);" />
<script>
    function disableButton(sender) { // Disable to prevent duplicate submission. Enabled in code behind
        if (Page_ClientValidate("DynamicForm")) {
            setTimeout(function () { $('#<%= submitButton.ClientID%>').attr("disabled", "true"); }, 0); // Asynchronously disable, otherwise disabled button won't submit first time
        }
     }
</script>
Private Sub submitbutton_Click(sender As Object, e As EventArgs) Handles submitButton.Click
    ...
    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "EnableButton", "$('#" + submitButton.ClientID + "').removeAttr('disabled');", True)
End Sub