Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
XML
<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");
});

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

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


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
Posted
Updated 29-Jul-10 9:17am
v2
Comments
PunkIsNotDead 29-Jul-10 16:08pm    
try you code, but with return false;

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

... And in button Delete set the property UseSubmitBehavior to false... if that doesn't work to you, just use a simple <input type="button" value="Delete" /> instead (there are some things that asp.net controls can't do! :)

1 solution

Try:
JavaScript
$('#<%=btnDelete.ClientID%>').attr("disabled", "true");

Refer: Disable submit button[^]

Further, viewstate shouldn't be the reason as the change made was client side.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900