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;
}
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