禁用按钮后为什么启用它? [英] Why is my button enabling after I disable it?

查看:135
本文介绍了禁用按钮后为什么启用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与GridView控件一起驻留在UpdatePanel中的按钮控件.该按钮最初是禁用的,但是当从GridView中选择一行时可以通过jQuery启用.这部分正常工作.

I have a button control that resides in an UpdatePanel along with a GridView control. The button is initially disabled but enabled via jQuery when a row from a GridView is selected. This part works correctly.

<asp:Button ID="btnDelete" Text="Delete Selected Row" onclick="btnDelete_Click" EnableViewState="false" Enabled="false" runat="server" />


$(''#<%=grdUsers.ClientID%> tr[id]'').click(function() {
    $(''#<%=btnDelete.ClientID%>'').removeAttr("disabled");
});


在按下按钮后,由于所选行将从网格中删除,因此再次禁用它.请注意,我什至没有编码删除逻辑,只是禁用了按钮.我试图在三个不同的地方禁用它:


After I press the button I disable it again since the selected row will be deleted from the grid. Note that I do not even have the delete logic coded yet, just the disabling of the button. I tried to disable it in three different places:

$(document).ready(function() {
    $(''#<%=btnDelete.ClientID%>'').attr("disabled", "disabled");
});


protected void btnDelete_Click(object sender, EventArgs e)
{
    btnDelete.Enabled = false;
}


protected void Page_Init(object sender, EventArgs e)
{
    btnDelete.Enabled = false;
}



我实际上可以看到该按钮在被按下后会被禁用,但是该按钮会快速重新单独启用.

可能是在回发之后,按钮的viewstate导致其被重新初始化为启用状态吗?我尝试关闭按钮上的ViewState,但这没有帮助.

Adam



I can actually see the button get disabled after it is pressed, but the button quickly re-enables on its own.

Could it be that after the postback the viewstate of the button is causing it to be reinitialized as enabled? I tried turning ViewState off on the button but that did not help.

Adam

推荐答案

(``#<%= grdUsers.ClientID%> tr [id]'').click(function(){
(''#<%=grdUsers.ClientID%> tr[id]'').click(function() {


(''#<%= btnDelete.ClientID%>'').removeAttr("disabled"); });
(''#<%=btnDelete.ClientID%>'').removeAttr("disabled"); });


在按下按钮后,由于所选行将从网格中删除,因此再次禁用它.请注意,我什至没有编码删除逻辑,只是禁用了按钮.我试图在三个不同的地方禁用它:


After I press the button I disable it again since the selected row will be deleted from the grid. Note that I do not even have the delete logic coded yet, just the disabling of the button. I tried to disable it in three different places:


(文档).ready(function(){
(document).ready(function() {


这篇关于禁用按钮后为什么启用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆