ASP.NET Button – prevent double clicks

by Evgeny Petrov on March 26th, 2009 | Posted in Revium Sandbox | Read the comments

Virtually every asp.net developer has met the situation when a page postback takes quite some time (this is often related to web service calls at back end) and it is required to prevent user from submitting the form twice. The task sounds easy, doesn’t it? Unfortunately there is no easy and straighforward way in ASP.NET to accomplish this.

The main problem is a default ASP.NET postback behaviour when a disabled html button (the techique is – to disable button straight after clicking) cannot submit the form. Other techiques like using html buttons, hidden fields to pass value to the server side and javascript calls to __DoPostback() are pretty cumbersome and far from being elegant.

Luckily I’ve come across the following method which is both elegant and simple:

Code behind:

protected override void OnInit (EventArgs e)
{
	// We need this to disable our button when submitting
	Form.SubmitDisabledControls = true;
	btnSubmit.UseSubmitBehavior = false;

	base.OnInit(e);
}

Page source code:

Enjoy!

Related posts:

  1. ASP.NET Button – prevent double clicks part 2
  2. Cross-domain login in ASP.NET
  3. Developing faster web forms in .NET
  4. Power of the ASP.NET MVC + jquery
  5. ASP.NET selectors in jquery

Tags: asp.net, jquery

« CSV parsing – the easy way!

Linq to SQL select and update oddity »

One Response to “ASP.NET Button – prevent double clicks”

  1. ASP.NET Button – prevent double clicks part 2 | Revium | Web Developers, Web Design, Melbourne says:
    June 2, 2010 at 2:05 pm

    [...] while ago Evgeny posted an article on how to prevent double clicks on buttons in ASP.Net. This solution was a little code heavy for my [...]

Leave a Reply

Click here to cancel reply.

Recent Articles

  • ISAF Sailing World Cup
  • Revium Supports the Prostate Cancer Foundation of Australia
  • Kentico FAQ Module
  • Advanced Visitor Tracking in Analytics
  • Kentico, Smart Search and filtering attachments
  • Enhancing JIRA’s Issue Navigator
  • Mobile Browsing
  • Revium help win gold for Australia

Twitter

  • All things Gold! http://t.co/9DkkjmAr 2012-09-13
  • Mat Belcher - our favourite London Gold Medalist dropped into the office to say thank you. http://t.co/TxHbe2y6 2012-09-13
  • You beauty - http://t.co/1kbcBZwg #london2012 @belcherpage2012 2012-08-10
  • More updates...

Revium Logo

  • Home
  • About
  • Expertise
  • Showcase
  • Contact

  • news
  • blog
  • sandbox
  • twitter
  • rss
  • visit our facebook page

We are Revium, hear us roar!

The news.

26 Feb

Revium Supports the Prostate Cancer Foundation of Australia

We here at Revium are proud to say that we are supporting the Prostate Cancer Foundation of Australia, this month we have been able…

Continue reading
View archive

The blog.

11 Apr

ISAF Sailing World Cup

Mat Belcher and his team have been successful in taking out round 3 of the ISAF Sailing World Cup in Palma de Mallorca a…

Continue reading
View archive

The sandbox.

20 Dec

Kentico, Smart Search and filtering attachments

We had a scenario recently where we had 2 indexes set up in Kentico to search different folders within our site. Everything worked as…

Continue reading
View archive

eNewsletter.

 

© Copyright 2013. All Rights Reserved.

Revium Pty Ltd

info@revium.com.au Work +61 3 9429 2000

10 Harvey Street
Richmond, Victoria, 3121 Australia
View map

Disclaimer and privacy Revium Pty Ltd

Find us: web development, seo

 
Partner logos