Reputation:
I want when user click on button,disable it and after do work enable it from code behind
i use below code but disable it and then enable it,because page load again and doesn't call button event click from code behind
ASPX
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
<div>
<asp:Button runat="server" ID="btnReg" OnClick="reg_Click" OnClientClick="disableButton();" Text="Click On Me..." />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnReg" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
JavaScript
function disableButton()
{
document.getElementById("<%=btnReg.ClientID%>").disabled = true;
}
Code behind
protected void reg_Click(object sender, EventArgs e)
{
//do work
btnReg.Enabled = true;
}
Upvotes: 2
Views: 2725
Reputation: 13250
Disable your button using javascript as shown:
document.getElementById("<%=btnReg.ClientID%>").disabled = true;
Enable it from codebehind as shown:
//after doing some logic
btnReg.Enabled = true;
UpdatePanel.Update();
For info read this
$(function() {
function doosomething()
{
document.getElementById("<%=btnReg.ClientID%>").enabled= true;
}
};
Call this function as soon as you disable the button from your codebehind as shown:
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "doosomething();", true);
Upvotes: 2