When you have client side script on the button to Disable the button, it prevents the buttons Click Event from being fired.
Steps to Reproduce:
See Attached Project
Actual Results:
Button is Disabled, but the Postback is canceled.
Expected Results:
Button should be disabled, and the Postback should still happen.
Disabling an ASPxButton inside it's Client Side Click Event stops the Postback.
Answers approved by DevExpress Support
Hi!
This behavior is by design. We suggest that you use UpdatePanel's client-side events to enable/disable your ASPxButton.
The following code will help you:
ASPX:
ASPx<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
ASPxButton1.SetEnabled(false);
}
function EndRequestHandler(sender, args) {
ASPxButton1.SetEnabled(true);
}
</script>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<dxe:ASPxButton ID="ASPxButton1" runat="server" ClientInstanceName="ASPxButton1" Text="ASPxButton" OnClick="ASPxButton1_Click">
</dxe:ASPxButton>
<dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="ASPxLabel">
</dxe:ASPxLabel>
</ContentTemplate>
</asp:UpdatePanel>
CS:
C#protected void ASPxButton1_Click(object sender, EventArgs e) {
ASPxLabel1.Text = "Callback";
System.Threading.Thread.Sleep(2000);
}
This approach is more robust than using the client SetEnabled function when handling the client-side OnClick event.
Thanks,
Andrew R
Hi Brien,
This ASPxButton behavior was designed to prevent a disabled button from doing a postback when it is being clicked or the DoClick client-side method is called.
Please explain your scenario and requirements in greater detail. We'll do our best to find a solution.
Thanks,
Andrew R
I have a donation page, that at the end of the process, the user clicks the "Complete Donation" button. I want to disable that button so they cannot click it a second time, which would cause their CC to be charged twice.
Hi Brien,
Thank you for the additional information. However, it's not quite clear what difficulties you are experiencing when implementing this functionality.
Could you please post here a small sample project demonstrating the problem? We'll research it and provide you with a possible solution.
Thanks,
Andrew R