Your strategic advantage starts here

Prevent Submitting an ASP.Net form Twice

Prevent Submitting an ASP.Net form Twice

This post describes how to prevent submitting an ASP.Net form twice.  I stumbled across a rather neat and handy way to achieve this by the following:

public void PreventMultipleClicks(Button button, Page page)
{
    button.Attributes.Add("onclick", "if(Page_ClientValidate()){this.disabled=true;this.value='Processing Request...';" + page.ClientScript.GetPostBackEventReference(button, String.Empty).ToString() + "}");
}

protected void Page_Load(object sender, EventArgs e)
{
    PreventMultipleClicks(submitRequest, this.Page);
}

I also re-label the button to say something meaningful (Such as ‘Processing Request…’ in this instance).  What this does is each time the page loads it binds the onclick event to my submit button (with an ID of ‘submitRequest’).  The onclick event disables and re-labels the submit button, and then posts the form.

 

 

Related Posts
Leave a Reply
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day