ASP.NET – Disabling the submit button to prevent double submissions

If a user clicks on a form submit button and the page response is slow, the user may often re-click that button. Because the original request has already been submitted, you may find that the user has made a double submission. In e-commerce sites, the double submission of a credit card payment may be very unpopular with your customers.

This is a common problem faced by web developers, and there are a variety of ways to try to prevent it. However, I have not seen a really elegant way to solve the problem, so I set about trying to find a simple and effective solution.

There were some key issues I wanted to address:

  1. I wanted to disable the button when it was clicked, but only if the page was valid
  2. I did not want to manually add code to every button in my application
  3. I did not want to break the existing validation, especially when using validation groups
  4. I wanted to preserve the CausesValidation property

To achieve these goals, I set about creating a custom button that inherited the standard ASP Button. This custom button would replace the existing buttons in my application.

First add a new class to your App_Code directory called “EnhancedButton” and then override the OnPreRender event:

Now, we add the following to our web.config to take advantage of the tagMapping feature:

The result is that all instances of standard Buttons are replaced with our new Enhanced custom button. You have no need to add extra code in every Page_Load. The Tag Mapping takes care of replacing the standard button across the web application.

And Voilà, our job is done!

An Open Letter to the People of Israel

When Adolf Hitler rose to power in 1933 on a wave of nationalism, born out of the failures of a nation after the Great War, he looked for someone to blame. Although anyone fulfilling the role of a non-German was considered fair game, but it was the German Jews that took the full force of the backlash. As Germany expanded its borders through invasion and annexation the rest of the world resorted to appeasement, scarred by memories of the Great War.

Anti-Semitism was a key policy of the National Socialists and in 1939 Adolf Eichmann started to systematically move Jews into designated areas of Polish cities, which was to be the start of the Nazi “Final Solution”. During the war the Nazis created Jewish ghettos across occupied Europe. Commonly a wall was built around the area, and the Jewish inhabitants were restricted from leaving the ghetto. Food and supplies were strictly controlled by the Nazis and crowded living conditions led to disease and starvation.
One of the most infamous ghettos was the Warsaw Ghetto that contained 300,000 – 400,000 people. In 1943 the Jewish population were being subjected to the second wave of deportations to concentration camps and by this time they realised that they were being sent to their deaths. An insurgency was born, and using a handful of small arms and improvised weapons, the inhabitants of the ghetto fought against a superior war machine. The main rebellion was over with a month, and at the end, 13,000 Jewish people had died. The remaining 50,000 inhabitants were captured and shipped off to concentration camps, mainly Treblinka.
Years before in 1922, the League of Nations (pre-cursor to the UN), granted the British a mandate over Palestine. Although Jewish emigration to Palestine had started some time before, it was the rise of Nazism in the 1930’s that started the “Fifth Aliyah”, bringing a quarter of a million Jews to settle in Palestine. In opposition to these large numbers of immigrants, an uprising, started by a general strike by the Arabs in Palestine led Britain to halt further Jewish immigration into Palestine in 1939.
By the end of World War II, the Jewish population of Palestine had increased to 33%, from 11% in 1922. After 1945, Britain struggled to control Palestine and became embroiled in an increasingly violent conflict with the Jews. On May 14, 1948, the day before the end of the British mandate, the Jewish Agency proclaimed independence, naming the country Israel. Eleven minutes after the Declaration of Independence was signed, US President Truman, recognised the State of Israel, and a nation was born.
Over the years since, Israel has expanded its borders through armed conflict with its neighbours, and now occupies much of this land. Throughout this expansion Israel has been appeased and although several UN mandates have been passed against Israel, many remain ignored. Israel has developed into a strong militarised nation with biological, chemical and nuclear capabilities. It remains the most powerful military force in the region.
In 1967, Israel took control of the Gaza strip, a piece of land bordering Israel and Egypt. It is roughly 41 kilometres long and between 6 – 12 kilometres wide.
In 1987 the “First Intifada” or the “War of Stones” started, and was a mass Palestinian uprising against Israeli rule. Action ranged from civil disobedience to violence. Many suspected Israeli collaborators were killed by their own people. The result was loss of life on both sides, but it also cemented Palestinian identity in the eyes of the rest of the world.
Since 1987, violence has never left the region. Tit-for-tat attacks have continued unabated and many lives have been lost. Peace treaties have been discussed, signed and ignored.
Under the Oslo Accords, Israel left the Gaza strip in 1994 and the area came under Palestinian control. From this date onwards Israel set about building a wall around Gaza, known as the”Israel – Gaza Strip Barrier”. There are three crossing points in the barrier, which are controlled by Israel, and are of crucial importance to the 1.4 million inhabitants of Gaza, who are unable to be self sufficient.
Regardless of who has controlled Gaza since, a steady stream of rocket attacks have hit Israeli cities, and Palestinian suicide bombers have been used to create havoc and fear.
In June 2007 both Egypt and Israel blockaded the Gaza strip and Israel sealed the borders and allowing only enough goods in to prevent a humanitarian crisis.
Now the Gaza strip is a ghetto. The inhabitants are walled in. One can draw parallels to the Warsaw ghetto in the 1940’s, but many who do are criticised, such as Pat Buchanan, who accused Israel of turning Gaza into a “concentration camp”.
One can now see a similarity between the Gazan insurgency and the Jewish insurgency in the Warsaw ghetto. Both fought a superior and better armed opponent in a guerrilla war. Both were confined to a piece of land, unable to move freely, with restricted access to work, food, or medical supplies.
It is a moral requirement that we see this situation as it is. The world still reels from the guilt of the holocaust, and appeases Israel because of it. But enough is enough. Israel has to be responsible for its actions. It has to realise that it cannot continue on this path, because ironically, it is this very path that has destroyed so much of its own. The Palestinians have nothing more to lose, and they know it. Israel is a hair’s breadth from making a decision it will long regret in the history of humanity. It is arguably on the brink of having committed war crimes against humanity and ethnic cleansing.
It is Israel that must make the first move. It holds the power and the keys to the kingdom. The only thing that the Palestinian authorities have left in their diplomatic armory is their refusal to recognise the State of Israel, and it is a worthless sticking point that both use to maintain the diabolical status-quo.
It is important that one realises that criticism of Israeli policies is not anti-Semitic. To draw an analogy with the Nazi era, one can criticise the Nazi state, whilst holding nothing against German people. It is an important differentiation to make between the crimes of a state and its people. The same can be said of Hamas and the people of Gaza.
We cannot undo history, so now we are only left with a valid two state solution that is equitable and honoured by both. There is no reason that the two nations cannot live side by side and prosper. 
Where the Nazis fostered the Jews as their nemesis, today it is the turn of Islamic fundamentalism. In reality it is nothing more than a crusade, aimed to gather a population and direct them against a common evil, and prevent them from looking inwards.
If we were able to truly reflect on ourselves and what we have become, I think we would have much to change.
Now that is change we can believe in.