Skip to content

DevExpress-Examples/asp-net-web-forms-button-disable-after-first-click

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Button for ASP.NET Web Forms - How to disable a button after the first click

This example demonstrates how to create a button and disable its client-side functionality after the first click.

Overview

Follow the steps below:

  1. Create a button and handle its client-side Click event. In the handler, do the following:

    • Call the button's SetEnabled method to disable its functionality on the client.
    • Send a postback to the server to prevent subsequent clicks.
    <dx:ASPxButton runat="server" ID="btnPurchase" ClientInstanceName="btnPurchase" OnClick="btnPurchase_Click"
        Text="Complete Purchase" AutoPostBack="False" ClientEnabled="True">
        <ClientSideEvents Click="OnClick" />
    </dx:ASPxButton>
    function OnClick(s,e){ 
        s.SetText('Purchased'); 
        s.SetEnabled(false);
        __doPostBack(s.name);
    }
  2. After you call the SetEnabled method to disable a button, the control does not pass its disabled state to the server on a postback. In this case, you should handle the button's server-side Click event and set the ClientEnabled property to false.

    protected void btnPurchase_Click(object sender, EventArgs e) {
        btnPurchase.Text = "Purchased";
        btnPurchase.ClientEnabled = false;
    }

Files to Review

About

Create a button and disable its client-side functionality after the first click.

Topics

Resources

License

Stars

Watchers

Forks