Click here to Skip to main content
15,860,861 members
Articles / Web Development / ASP.NET

How to do a click once button in AJAX

Rate me:
Please Sign up or sign in to vote.
2.00/5 (4 votes)
7 Feb 2008CPOL 21.4K   13   3
A click once button.

Introduction

This code makes a button clickable only once.

Background

I did a page with an UpdatePanel on it.

Since I had a lot of controls between the order button (BESTÄLL) and the panel, I did the order button external to the panel.

I needed the order button clickable only once, in order to achieve this:

Two.JPG

Using the Code

I added an onSubmit method to the form:

ASP.NET
<form id="form1" runat="server" 
  onsubmit="document.form1.btnOrder.disabled = true;return true;"> 
...
<button id="btnOrder" style="MARGIN-LEFT: 20%" 
  runat="server" text="BESTÄLL"></button>

Points of Interest

The key to make it work is:

JavaScript
return true;

Otherwise, the server side event doesn't trigger.

Comments

I would appreciate feedback and tips on a more .NET-tish way of doing this.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
General[My vote of 1] Not working Pin
Vimalsoft(Pty) Ltd20-Aug-09 3:46
professionalVimalsoft(Pty) Ltd20-Aug-09 3:46 
GeneralUse an extender, create a behavior Pin
alexgoodbox7-Feb-08 17:49
alexgoodbox7-Feb-08 17:49 
GeneralOr Else Pin
djsolid7-Feb-08 2:04
djsolid7-Feb-08 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.