Wednesday 17 June 2015

Prevent Button Double Click ASP.NET Code Behind

Disable ASP.NET Button after click to prevent the double click and change button text to Loading/Please Wait.

Design :

<asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" />


Code Behind :

//Here javascript added to the button at page load.

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string strProcessScript = "this.value='Processing...';this.disabled=true;";
            Button1.Attributes.Add("onclick", strProcessScript + ClientScript.GetPostBackEventReference(Button1, "").ToString());
        }
        catch { }
    }

//After Button click method wait for 5 Second to check the result.
protected void Button1_Click(object sender, EventArgs e)
    {
       
                Thread.Sleep(5000);
   
    }


Then check you result.

If you have any issue then let me know.

No comments:

Post a Comment